homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ConfigParser does not handle square brackets in section name
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: [doc] Explain ConfigParser 'valid section name' and .SECTCRE
View: 20923
Assigned To: Nosy List: r.david.murray, xflr6
Priority: normal Keywords:

Created on 2015年01月22日 15:58 by xflr6, last changed 2022年04月11日 14:58 by admin. This issue is now closed.

Messages (2)
msg234497 - (view) Author: Sebastian Bank (xflr6) Date: 2015年01月22日 15:58
ConfigParser parses section lines containing square brackets like '[spam [eggs] spam]' up to the first instead of the last occurrence of ']' preventing roundtrips:
>>> s = StringIO()
>>> c1 = ConfigParser()
>>> c1.add_section('spam [eggs]')
>>> c1.write(s)
>>> s.seek(0)
>>> c2 = ConfigParser()
>>> c2.readfp(s)
>>> assert c1.sections() == c2.sections() # fails
Potential fix: change the second line of SECTCRE from r'(?P<header>[^]]+)' to r'(?P<header>.+?)'.
If the parsing behaviour cannot be changed, the user should at least be warned about supplying data that breaks the roundtrip.
msg234498 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年01月22日 16:06
This is a duplicate of issue 20923, which was rejected. To argue against the rejection you probably need to provide evidence that this is something that is actually supported by other common ini parsers. And that evidence should be posted to issue 20923.
History
Date User Action Args
2022年04月11日 14:58:12adminsetgithub: 67490
2015年01月22日 16:06:52r.david.murraysetstatus: open -> closed

superseder: [doc] Explain ConfigParser 'valid section name' and .SECTCRE

nosy: + r.david.murray
messages: + msg234498
resolution: duplicate
stage: resolved
2015年01月22日 15:58:05xflr6create

AltStyle によって変換されたページ (->オリジナル) /