detect attempts to repeat anchors (fixes bug #130748)

This commit is contained in:
Fredrik Lundh 2001-02-18 21:04:48 +00:00
parent 8ac3627b91
commit c0c7ee3a65
2 changed files with 5 additions and 0 deletions

View File

@ -446,6 +446,7 @@ def _parse(source, state):
min, max = 0, 1 min, max = 0, 1
elif this == "*": elif this == "*":
min, max = 0, MAXREPEAT min, max = 0, MAXREPEAT
elif this == "+": elif this == "+":
min, max = 1, MAXREPEAT min, max = 1, MAXREPEAT
elif this == "{": elif this == "{":
@ -475,6 +476,8 @@ def _parse(source, state):
if subpattern: if subpattern:
item = subpattern[-1:] item = subpattern[-1:]
else: else:
item = None
if not item or (len(item) == 1 and item[0][0] == AT):
raise error, "nothing to repeat" raise error, "nothing to repeat"
if item[0][0] in (MIN_REPEAT, MAX_REPEAT): if item[0][0] in (MIN_REPEAT, MAX_REPEAT):
raise error, "multiple repeat" raise error, "multiple repeat"

View File

@ -636,4 +636,6 @@ xyzabc
(r'(?i)m+', 'MMM', SUCCEED, 'found', 'MMM'), (r'(?i)m+', 'MMM', SUCCEED, 'found', 'MMM'),
(r'(?i)[M]+', 'MMM', SUCCEED, 'found', 'MMM'), (r'(?i)[M]+', 'MMM', SUCCEED, 'found', 'MMM'),
(r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'), (r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'),
# bug 130748: ^* should be an error (nothing to repeat)
(r'^*', '', SYNTAX_ERROR),
] ]