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

@@ -315,6 +315,12 @@ class Re2RegexpTest(ReRegexpTest):
re2.purge()
self.assertEqual(re2._Regexp._make.cache_info().currsize, 0)
def test_options(self):
opt = re2.Options()
opt.case_sensitive = False
r = re2.compile('test', opt)
self.assertIsNotNone(r.search('TEST'))
self.assertIsNotNone(re2.search(r, 'TEST'))
class Re2EscapeTest(parameterized.TestCase):
"""Contains tests that apply to the re2 module only.