mirror of
https://github.com/python/cpython.git
synced 2025-08-08 19:09:46 +00:00
[3.12] gh-109747: Improve errors for unsupported look-behind patterns (GH-109859) (GH-110859)
Now re.error is raised instead of OverflowError or RuntimeError for
too large width of look-behind pattern.
The limit is increased to 2**32-1 (was 2**31-1).
(cherry picked from commit e2b3d831fd
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
12b9cb80be
commit
a2cc9a4c3a
6 changed files with 46 additions and 13 deletions
|
@ -149,6 +149,8 @@ def _compile(code, pattern, flags):
|
|||
emit(0) # look ahead
|
||||
else:
|
||||
lo, hi = av[1].getwidth()
|
||||
if lo > MAXCODE:
|
||||
raise error("looks too much behind")
|
||||
if lo != hi:
|
||||
raise error("look-behind requires fixed-width pattern")
|
||||
emit(lo) # look behind
|
||||
|
@ -549,7 +551,7 @@ def _compile_info(code, pattern, flags):
|
|||
else:
|
||||
emit(MAXCODE)
|
||||
prefix = prefix[:MAXCODE]
|
||||
emit(min(hi, MAXCODE))
|
||||
emit(hi)
|
||||
# add literal prefix
|
||||
if prefix:
|
||||
emit(len(prefix)) # length
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue