Issue 30 in iniparse: Leading whitespace in front of a value make the parsing fail

0 views
Skip to first unread message

inip...@googlecode.com

unread,
Jun 13, 2012, 4:32:04 AM6/13/12
to iniparse...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 30 by batiste....@gmail.com: Leading whitespace in front of a
value make the parsing fail
http://code.google.com/p/iniparse/issues/detail?id=30

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

inip...@googlecode.com

unread,
Jun 13, 2012, 5:06:21 AM6/13/12
to iniparse...@googlegroups.com

Comment #1 on issue 30 by batiste....@gmail.com: Leading whitespace in
front of a value make the parsing fail
http://code.google.com/p/iniparse/issues/detail?id=30

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.

Attachments:
leading-whitespace.patch 2.1 KB

inip...@googlecode.com

unread,
Jun 17, 2012, 9:04:09 AM6/17/12
to iniparse...@googlegroups.com

Comment #2 on issue 30 by psobe...@gmail.com: Leading whitespace in front
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.

Reply all
Reply to author
Forward
0 new messages