python: fix re2.search(compiled, text)

The old code was accidentally recompiling the pattern
and losing the options, both inefficient and incorrect.
Thanks to @MajorTanya for the excellent diagnosis.

This bug was introduced in CL 60290 and then copied
over from the Abseil branch.

Fixes #558.

Change-Id: I072707003b444fb0934a310e14147b4d65b9da11
Reviewed-on: https://code-review.googlesource.com/c/re2/+/63830
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Russ Cox
2025-08-02 08:09:01 -07:00
committed by Russ Cox
parent 362c5596a7
commit 45150b3d15
2 changed files with 7 additions and 1 deletions

View File

@@ -64,7 +64,7 @@ def compile(pattern, options=None):
if options:
raise error('pattern is already compiled, so '
'options may not be specified')
pattern = pattern._pattern
return pattern
options = options or Options()
values = tuple(getattr(options, name) for name in Options.NAMES)
return _Regexp._make(pattern, values)