summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2000-10-07 17:38:23 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2000-10-07 17:38:23 (GMT)
commit13ac9926ac43d3bff39a08301696105208774b6e (patch)
tree483ca7a4344c3a573e6f3f91262f111c376560e4 /Lib
parent5c0b43d1e26e28608170baf2887a82124b62fa36 (diff)
downloadcpython-13ac9926ac43d3bff39a08301696105208774b6e.zip
cpython-13ac9926ac43d3bff39a08301696105208774b6e.tar.gz
cpython-13ac9926ac43d3bff39a08301696105208774b6e.tar.bz2
Fixed too ambitious "nothing to repeat" check. Closes bug #114033.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/sre_compile.py2
-rw-r--r--Lib/sre_constants.py2
-rw-r--r--Lib/sre_parse.py2
-rwxr-xr-xLib/test/re_tests.py3
4 files changed, 6 insertions, 3 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index 97a57e2..dc508e5 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -222,7 +222,7 @@ def _optimize_charset(charset, fixup):
def _simple(av):
# check if av is a "simple" operator
lo, hi = av[2].getwidth()
- if lo == 0:
+ if lo == 0 and hi == MAXREPEAT:
raise error, "nothing to repeat"
return lo == hi == 1 and av[2][0][0] != SUBPATTERN
diff --git a/Lib/sre_constants.py b/Lib/sre_constants.py
index 5a20930..ea649c0 100644
--- a/Lib/sre_constants.py
+++ b/Lib/sre_constants.py
@@ -9,6 +9,8 @@
# See the sre.py file for information on usage and redistribution.
#
+MAXREPEAT = 65535
+
# should this really be here?
class error(Exception):
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 9cbbc02..7c36d4f 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -12,8 +12,6 @@ import string, sys
from sre_constants import *
-MAXREPEAT = 65535
-
SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{"
diff --git a/Lib/test/re_tests.py b/Lib/test/re_tests.py
index 7c54175..2d3155d 100755
--- a/Lib/test/re_tests.py
+++ b/Lib/test/re_tests.py
@@ -615,10 +615,13 @@ xyzabc
# bug 112468: various expected syntax errors
('(', '', SYNTAX_ERROR),
('[\\41]', '!', SUCCEED, 'found', '!'),
+ # bug 114033: nothing to repeat
+ (r'(x?)?', 'x', SUCCEED, 'found', 'x'),
# bug 115040: rescan if flags are modified inside pattern
(r' (?x)foo ', 'foo', SUCCEED, 'found', 'foo'),
# bug 115618: negative lookahead
(r'(?<!abc)(d.f)', 'abcdefdof', SUCCEED, 'found', 'dof'),
# bug 116251: character class bug
(r'[\w-]+', 'laser_beam', SUCCEED, 'found', 'laser_beam'),
+
]