Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0c7ee3

Browse files
author
Fredrik Lundh
committed
detect attempts to repeat anchors (fixes bug #130748)
1 parent 8ac3627 commit c0c7ee3

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lib/sre_parse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ def _parse(source, state):
446446
min, max = 0, 1
447447
elif this == "*":
448448
min, max = 0, MAXREPEAT
449+
449450
elif this == "+":
450451
min, max = 1, MAXREPEAT
451452
elif this == "{":
@@ -475,6 +476,8 @@ def _parse(source, state):
475476
if subpattern:
476477
item = subpattern[-1:]
477478
else:
479+
item = None
480+
if not item or (len(item) == 1 and item[0][0] == AT):
478481
raise error, "nothing to repeat"
479482
if item[0][0] in (MIN_REPEAT, MAX_REPEAT):
480483
raise error, "multiple repeat"

Lib/test/re_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,4 +636,6 @@
636636
(r'(?i)m+', 'MMM', SUCCEED, 'found', 'MMM'),
637637
(r'(?i)[M]+', 'MMM', SUCCEED, 'found', 'MMM'),
638638
(r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'),
639+
# bug 130748: ^* should be an error (nothing to repeat)
640+
(r'^*', '', SYNTAX_ERROR),
639641
]

0 commit comments

Comments
 (0)