New submission from Florian Bruhin:
When adding something to a configparser instance which has a key beginning with
a comment char, it writes the data to a file without generating an error, and
when reading the file back obviously the data is different as it's a comment:
>>> cp = configparser.ConfigParser()
>>> cp.read_dict({'DEFAULT': {';foo': 'bar'}})
>>> cp.write(sys.stdout)
[DEFAULT]
;foo = bar
This was discussed on python-dev here:
https://mail.python.org/pipermail/python-dev/2014-April/134293.html
Of course there are other corner cases as well, like having a key like "[foo]"
or "=bar".
I think whatever data I pass into a configparser should also come out again
when reading the file back.
Since there's no escaping in configparser, I think the ideal solution would be
configparser refusing to write ambigious values.
While this is technically a backwards-incompatible change, applications doing
this were broken in the first place, so validation while writing will not break
anything.
Validating when setting values would be better of course, but this can
potentially break applications where configparser is used without actually
writing a file.
----------
components: Library (Lib)
messages: 218463
nosy: The Compiler, lukasz.langa
priority: normal
severity: normal
status: open
title: configparser accepts keys beginning with comment_chars when writing
type: behavior
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue21498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com