Repository navigation
[doc] Explain ConfigParser 'valid section name' and .SECTCRE #65122
Copy link
Copy link
Closed
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc direasytype-featureA feature request or enhancementA feature request or enhancement
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/terryjreedy'
closed_at = <Date 2022-02-22.18:46:35.431>
created_at = <Date 2014-03-14.14:21:45.867>
labels = ['easy', '3.9', '3.10', '3.11', 'type-feature', 'docs']
title = "[doc] Explain ConfigParser 'valid section name' and .SECTCRE"
updated_at = <Date 2022-02-22.18:46:35.431>
user = 'https://bugs.python.org/miloskomarcevic'bugs.python.org fields:
activity = <Date 2022-02-22.18:46:35.431>
actor = 'iritkatriel'
assignee = 'terry.reedy'
closed = True
closed_date = <Date 2022-02-22.18:46:35.431>
closer = 'iritkatriel'
components = ['Documentation']
creation = <Date 2014-03-14.14:21:45.867>
creator = 'miloskomarcevic'
dependencies = []
files = []
hgrepos = []
issue_num = 20923
keywords = ['patch', 'easy']
message_count = 23.0
messages = ['213554', '213609', '213678', '213687', '234954', '255263', '255269', '255277', '255278', '255279', '255281', '255304', '255325', '255368', '255369', '412197', '413270', '413271', '413292', '413727', '413734', '413738', '413739']
nosy_count = 12.0
nosy_names = ['terry.reedy', 'vstinner', 'r.david.murray', 'docs@python', 'lukasz.langa', 'python-dev', 'miloskomarcevic', 'xflr6', 'spaceone', 'miss-islington', 'iritkatriel', 'vidhya']
pr_nums = ['31359', '31413', '31506', '31507']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue20923'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc direasytype-featureA feature request or enhancementA feature request or enhancement
Activity
miloskomarcevic commentedon Mar 14, 2014
It would be good if ConfigParser supported angled brackets in section names by being greedy when parsing.
For example, section:
[Test[2]_foo]
gets parsed as:
Test[2
terryjreedy commentedon Mar 15, 2014
This is invalid as a bug report, unless one considers that the presence of '_foo]' on the same line should have raised an exception. As an enhancement request, I think it should be rejected.
ConfigParser configuration language is based on msdos/windows .ini files. Similar files are used on windows. "A configuration file consists of sections, each led by a [section] header," That and "The section name appears on a line by itself, in square brackets ([ and ])." from
https://en.wikipedia.org/wiki/.ini#Sections
mark [] as delimiters. I am rather sure that no other language/system allows square brackets in the section name. If you know differently, please present evidence. Unescaped delimiters are generally not allowed between delimiters unless there is a semantic reason to have nesting, and there is not one here. Parentheses, angle brackets, and curly brackets (and more from the rest of Unicode) are available to use. The request here is similar to asking that
'abc'cd'
be parsed as one string. Parsing nested constructs is much more complicated than parsing flat constructs.
[-]ConfigParser should be greedy when parsing section name[/-][+]ConfigParser should nested [] in section names.[/+]miloskomarcevic commentedon Mar 15, 2014
Thanks for the exhaustive explanation.
I did however come across a proprietary application that stores it's configuration in an INI like file that exhibits this corner case behaviour with section names, hence the suggestion for enhancement.
terryjreedy commentedon Mar 15, 2014
I see. Perhaps it uses a proprietary .ini reader ;-).
xflr6 commentedon Jan 29, 2015
If this is the intended behaviuour, I guess ConfigParser should warn the user if he supplies a section name with a ']' (prevent failed roundtrips).
See http://bugs.python.org/issue23301
The current behaviour looks like the opposite of Postel's law.
spaceone commentedon Nov 24, 2015
IMHO your rejection is stupid. User input should always be validated.
At least a ValueError should be raised if add_section() is called with a string containing ']\x00\n['. As this will always create a broken configuration.
Otherwise ConfigParser cannot be used to write new config files without having deeper knowledge about the implementation.
bitdancer commentedon Nov 24, 2015
The enhancement request was rejected. At this point I think it would be better to open a new bug requesting that an error be raised if the supplied section name contains a ']'. The question there is if there are backward compatibility issues. That can be discussed on the new issue you open.
terryjreedy commentedon Nov 24, 2015
Sebastian: you have it backwards. A paraphrase of Postel's recommendation (calling it a Law is wrong) is 'accept dirty data, emit clean data'. This is the current behavior. See https://en.wikipedia.org/wiki/Robustness_principle. This article also explains the opposite viewpoint, that dirty data should be rejected, as SpaceOne is suggesting.
SpaceOne: unless it is your intention to discourage people from volunteering their time to respond to issues raised on the tracker, you should read what they write more carefully and think more carefully about how you express your opinions. If you really want a ValueError here, open an new enhancement issue for 3.6.
spaceone commentedon Nov 24, 2015
Sorry about that!
I created http://bugs.python.org/issue25723.
xflr6 commentedon Nov 24, 2015
Terry: I am not so sure about that interpretation. Do we agree that the INI-files are the data/message? ConfigParser refuses to accept dirty INI-Files (with ']' in section names) but will produce this kind of files.
I we see the arguments given to ConfigParser as data/message, it does indeed accept dirty data as you say, but still it does not emit clean one in that case, right?
13 remaining items
iritkatriel commentedon Jan 31, 2022
The comment Terry suggests to add (see https://bugs.python.org/issue20923#msg255304) could be placed in this paragraph:
https://docs.python.org/3/library/configparser.html#supported-ini-file-structure
[-]Explain ConfigParser 'valid section name' and .SECTCRE[/-][+][doc] Explain ConfigParser 'valid section name' and .SECTCRE[/+]Vidhyavinu commentedon Feb 14, 2022
I am newbie to Python developer group and have the document source build and compiled successfully.
Is this issue updated in the document.
I would like to work on this if this is not closed.
Please let me know.
Thanks
iritkatriel commentedon Feb 14, 2022
It’s still open. Go for it.
Vidhyavinu commentedon Feb 15, 2022
Thanks.
A pull request is created at #31359.
iritkatriel commentedon Feb 22, 2022
New changeset bba8008 by vidhya in branch 'main':
bpo-20923 : [doc] Explain ConfigParser 'valid section name' and .SECTCRE (GH-31413)
bba8008
miss-islington commentedon Feb 22, 2022
New changeset a7af34d by Miss Islington (bot) in branch '3.10':
[3.10] bpo-20923 : [doc] Explain ConfigParser 'valid section name' and .SECTCRE (GH-31413) (GH-31506)
a7af34d
miss-islington commentedon Feb 22, 2022
New changeset 2387aea by Miss Islington (bot) in branch '3.9':
[3.9] bpo-20923 : [doc] Explain ConfigParser 'valid section name' and .SECTCRE (GH-31413) (GH-31507)
2387aea
iritkatriel commentedon Feb 22, 2022
Thank you @Vidhya!