summaryrefslogtreecommitdiff
path: root/Lib/sre_compile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-03 11:04:19 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-03 11:04:19 +0200
commit83e802796c80f46be616b48020356f7f51be533d (patch)
treee896b143abc3523f96e20d88ebcc22512af16aa7 /Lib/sre_compile.py
parent32ca3dcb97a75c05dc2b90c88bbf82a541c57c61 (diff)
downloadcpython-git-83e802796c80f46be616b48020356f7f51be533d.tar.gz
Issue #22818: Splitting on a pattern that could match an empty string now
raises a warning. Patterns that can only match empty strings are now rejected.
Diffstat (limited to 'Lib/sre_compile.py')
-rw-r--r--Lib/sre_compile.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index 1241a01c3e..30a5fae485 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -414,8 +414,11 @@ def _compile_info(code, pattern, flags):
# this contains min/max pattern width, and an optional literal
# prefix or a character map
lo, hi = pattern.getwidth()
+ if hi > MAXCODE:
+ hi = MAXCODE
if lo == 0:
- return # not worth it
+ code.extend([INFO, 4, 0, lo, hi])
+ return
# look for a literal prefix
prefix = []
prefixappend = prefix.append
@@ -495,10 +498,7 @@ def _compile_info(code, pattern, flags):
else:
emit(MAXCODE)
prefix = prefix[:MAXCODE]
- if hi < MAXCODE:
- emit(hi)
- else:
- emit(0)
+ emit(min(hi, MAXCODE))
# add literal prefix
if prefix:
emit(len(prefix)) # length