Averroes / iniparse

Other
0 stars 0 forks source link

Leading whitespace in front of a value make the parsing fail #30

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a ini file value with a leading white space
2. To access the value

The treatment of leading white spaces is not really well defined:

http://en.wikipedia.org/wiki/INI_file#Whitespace

The the doc definitely says that some implementation ignores them. In the case 
of iniparse the name=value pair becomes completely unavailable.

I can't imagine a scenario where this could be desired.

The change might as simple as:

http://code.google.com/p/iniparse/source/browse/trunk/iniparse/ini.py#

line 131 in iniparse/ini.py
-name = m.group('name').rstrip()
+name = m.group('name').strip()

line 135 in iniparse/ini.py
-name = m.group('name').rstrip()
+name = m.group('name').strip()

Cheers,
Batiste

Original issue reported on code.google.com by batiste....@gmail.com on 13 Jun 2012 at 8:32

GoogleCodeExporter commented 9 years ago
Here is a patch.

The tests seems to pass (I have the same number of failure). The only new 
failure I couldn't fix is test_fuzz.test_fuzz test.

The fix makes options like the following valid:

         ;D/V{q]`9F!jh v]Y 7l={]HCA7L`nE)

The only problem here seem to be the leading spaces that are added in 
good_lines. ConfigParser cannot handle.

I don't know how important it is for iniparse to mimic ConfigParser so I let 
you decide what to do with this patch.

Original comment by batiste....@gmail.com on 13 Jun 2012 at 9:06

Attachments:

GoogleCodeExporter commented 9 years ago
Older Pythons used to reject leading whitespace, but Python 3 seems to accept 
them, so I think it's time for iniparse to accept them as well.

Original comment by psobe...@gmail.com on 17 Jun 2012 at 1:04