Raise re2.error instead of crashing.

Fixes #484.

Change-Id: I152b5ed8a6358d2d74f553bde2e66f2e50cfba1d
Reviewed-on: https://code-review.googlesource.com/c/re2/+/62890
Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
Reviewed-by: Paul Wankadia <junyer@google.com>
This commit is contained in:
Paul Wankadia
2024-03-17 13:23:12 +00:00
parent db46d1e11e
commit 1250a99301
3 changed files with 17 additions and 2 deletions

View File

@@ -477,6 +477,13 @@ class FilterTest(absltest.TestCase):
# Verify whether the underlying RE2 object is usable.
self.assertEqual(0, f.re(2).groups)
def test_issue_484(self):
# Previously, the shim would dereference a null pointer and crash.
f = re2.Filter()
with self.assertRaisesRegex(re2.error,
r'Match\(\) called before compiling'):
f.Match('')
if __name__ == '__main__':
absltest.main()