Skip to content

ConfigParser does not handle square brackets in section name #67490

Closed

Description

@xflr6
mannequin
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']

    Activity

    1. xflr6 commented on Jan 22, 2015

      xflr6mannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jan 22, 2015
    3. bitdancer commented on Jan 22, 2015

      @bitdancer
      Member

      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.

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions