[Python-Dev] ConfigParser mangles keys with special chars

Florian Bruhin me at the-compiler.org
Fri Apr 25 16:22:06 CEST 2014


Hi,

I noticed configparser does behave in a surprising way when a key
has a special meaning in ini-format.

Consider this example:

    >>> cp = configparser.ConfigParser()
    >>> cp.read_dict({'DEFAULT': {';foo': 'bar'}})
    >>> cp.write(sys.stdout)
    [DEFAULT]
    ;foo = bar

Now when reading this again, ";foo = bar" will be a comment and
ignored. There's probably similiar behaviour in other corner cases
(like if you'd use "[foo]" as key for example).

While it seems ConfigParser doesn't do any escaping as all, I'm
thinking it should at least raise some exception when such a value is
trying to be set.

I'd expect writing something and then reading it back via the same
configparser to *always* result in the same data, as long as writing
worked without error.

Thoughts? Should I submit a bug report?

Florian

-- 
() ascii ribbon campaign - stop html mail    www.asciiribbon.org
/\ www.the-compiler.org  | I love long mails http://email.is-not-s.ms/
To give happiness is to deserve happiness. 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140425/2c50c918/attachment.sig>


More information about the Python-Dev mailing list