Skip to content
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

Wrong or missing exception when compiling regexes with recursive named backreferences #68768

Closed
dhaffey mannequin opened this issue Jul 7, 2015 · 5 comments
Closed
Assignees
Labels
topic-regex type-bug An unexpected behavior, bug, or error

Comments

@dhaffey
Copy link
Mannequin

dhaffey mannequin commented Jul 7, 2015

BPO 24580
Nosy @benjaminp, @ezio-melotti, @serhiy-storchaka
Files
  • re_open_group_symbolic_ref.patch
  • re_open_group_symbolic_ref-3.4.patch
  • 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/serhiy-storchaka'
    closed_at = <Date 2015-12-19.21:26:32.930>
    created_at = <Date 2015-07-07.01:25:41.905>
    labels = ['expert-regex', 'type-bug']
    title = 'Wrong or missing exception when compiling regexes with recursive named backreferences'
    updated_at = <Date 2015-12-19.21:26:32.928>
    user = 'https://bugs.python.org/dhaffey'

    bugs.python.org fields:

    activity = <Date 2015-12-19.21:26:32.928>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-12-19.21:26:32.930>
    closer = 'serhiy.storchaka'
    components = ['Regular Expressions']
    creation = <Date 2015-07-07.01:25:41.905>
    creator = 'dhaffey'
    dependencies = []
    files = ['39879', '39880']
    hgrepos = []
    issue_num = 24580
    keywords = ['patch']
    message_count = 5.0
    messages = ['246390', '246396', '246397', '246913', '256740']
    nosy_count = 6.0
    nosy_names = ['benjamin.peterson', 'ezio.melotti', 'mrabarnett', 'dhaffey', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue24580'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @dhaffey
    Copy link
    Mannequin Author

    dhaffey mannequin commented Jul 7, 2015

    Error reporting for recursive backreferences in regexes isn't consistent across both types of backref. Here's the exception for a recursive numeric backref:

    >>> import re
    >>> re.compile(r'(\1)')
    Traceback (most recent call last):
        ...
    sre_constants.error: cannot refer to an open group at position 1

    Here's what I'm seeing on the 3.5 branch for a named backref:

    >>> re.compile(r'(?P<spam>(?P=spam))')
    Traceback (most recent call last):
        ...
    RecursionError: maximum recursion depth exceeded

    Which is an improvement over 3.4 and below, where compilation succeeds and appears to treat (?P=spam) as valid but unmatchable.

    @dhaffey dhaffey mannequin added topic-regex type-bug An unexpected behavior, bug, or error labels Jul 7, 2015
    @serhiy-storchaka serhiy-storchaka self-assigned this Jul 7, 2015
    @serhiy-storchaka
    Copy link
    Member

    Here is a patch that forbids symbolic references to opened groups in 3.5+.

    @serhiy-storchaka
    Copy link
    Member

    It is questionable if an exception should be raised in older Python versions. Here is a patch for 3.4 that just issues a warning.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 18, 2015

    New changeset 361d7af9396e by Serhiy Storchaka in branch '3.5':
    Issue bpo-24580: Symbolic group references to open group in re patterns now are
    https://hg.python.org/cpython/rev/361d7af9396e

    New changeset 4d3557500019 by Serhiy Storchaka in branch 'default':
    Issue bpo-24580: Symbolic group references to open group in re patterns now are
    https://hg.python.org/cpython/rev/4d3557500019

    @serhiy-storchaka
    Copy link
    Member

    It is too late for 3.4, and I left 2.7 as is. Reopen issue if you think that it is worth to add a warning to 2.7.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-regex type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant