pixelb / crudini

A utility for manipulating ini files
GNU General Public License v2.0
443 stars 63 forks source link

Fails to read the first section if the file has a BOM #103

Closed peterhoeg closed 3 months ago

peterhoeg commented 3 months ago

crudini fails to read the first section if the file has a BOM. Before we get into the BOM vs no BOM discussion, I would like to point out that the file was generated by a program that expects a BOM.

Here is the test file:

$ cat test.ini

[foo]
bar = baz

[woot]
hello = world

When the file has a BOM, we are not able to read the first section - the 2nd is fine:

$ file *
test.ini: Unicode text, UTF-8 (with BOM) text

$ crudini --get test.ini foo 
Section not found: foo

$ crudini --get test.ini woot
hello

But if we strip the BOM, we can:

$ sed -i $'1s/^\uFEFF//' test.ini 

$ file *
test.ini: ASCII text

$ crudini --get test.ini foo
bar

$ crudini --get test.ini woot
hello

This might be an iniparse issue of course (without having looked at the code).

pixelb commented 3 months ago

Right. We should support this, and also maintain the BOM if updating such a file