Skip to content

ConfigParser does not handle square brackets in section name #67490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xflr6 mannequin opened this issue Jan 22, 2015 · 2 comments
Closed

ConfigParser does not handle square brackets in section name #67490

xflr6 mannequin opened this issue Jan 22, 2015 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xflr6
Copy link
Mannequin

xflr6 mannequin commented Jan 22, 2015

BPO 23301
Nosy @bitdancer, @xflr6
Superseder
  • bpo-20923: [doc] Explain ConfigParser 'valid section name' and .SECTCRE
  • 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 = None
    closed_at = <Date 2015-01-22.16:06:52.188>
    created_at = <Date 2015-01-22.15:58:05.320>
    labels = ['type-bug', 'library']
    title = 'ConfigParser does not handle square brackets in section name'
    updated_at = <Date 2015-01-22.16:06:52.186>
    user = 'https://github.com/xflr6'

    bugs.python.org fields:

    activity = <Date 2015-01-22.16:06:52.186>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-01-22.16:06:52.188>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2015-01-22.15:58:05.320>
    creator = 'xflr6'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 23301
    keywords = []
    message_count = 2.0
    messages = ['234497', '234498']
    nosy_count = 2.0
    nosy_names = ['r.david.murray', 'xflr6']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '20923'
    type = 'behavior'
    url = 'https://bugs.python.org/issue23301'
    versions = ['Python 2.7', 'Python 3.4']

    @xflr6
    Copy link
    Mannequin Author

    xflr6 mannequin commented Jan 22, 2015

    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.

    @xflr6 xflr6 mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 22, 2015
    @bitdancer
    Copy link
    Member

    bitdancer commented Jan 22, 2015

    This is a duplicate of bpo-20923 (#65122), 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 bpo-20923.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant