diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-03 09:04:19 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-03 09:04:19 (GMT) |
commit | 83e802796c80f46be616b48020356f7f51be533d (patch) | |
tree | e896b143abc3523f96e20d88ebcc22512af16aa7 /Lib/sre_compile.py | |
parent | 32ca3dcb97a75c05dc2b90c88bbf82a541c57c61 (diff) | |
download | cpython-83e802796c80f46be616b48020356f7f51be533d.zip cpython-83e802796c80f46be616b48020356f7f51be533d.tar.gz cpython-83e802796c80f46be616b48020356f7f51be533d.tar.bz2 |
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.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py index 1241a01..30a5fae 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 |