summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMa Lin <animalize@users.noreply.github.com>2022-04-03 16:16:20 (GMT)
committerGitHub <noreply@github.com>2022-04-03 16:16:20 (GMT)
commit6e3eee5c11b539e9aab39cff783acf57838c355a (patch)
tree29ee6720d249adfe5864ab9f09d7cb54d9f35238 /Lib/test
parentb82cdd1dac9a9be52051abd90a1ce69236ac41f4 (diff)
downloadcpython-6e3eee5c11b539e9aab39cff783acf57838c355a.zip
cpython-6e3eee5c11b539e9aab39cff783acf57838c355a.tar.gz
cpython-6e3eee5c11b539e9aab39cff783acf57838c355a.tar.bz2
bpo-23689: re module, fix memory leak when a match is terminated by a signal or memory allocation failure (GH-32283)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_re.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index f1e5af4..553eb4c 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1643,9 +1643,12 @@ class ReTests(unittest.TestCase):
long_overflow = 2**128
self.assertRaises(TypeError, re.finditer, "a", {})
with self.assertRaises(OverflowError):
- _sre.compile("abc", 0, [long_overflow], 0, {}, ())
+ _sre.compile("abc", 0, [long_overflow], 0, {}, (), 0)
with self.assertRaises(TypeError):
- _sre.compile({}, 0, [], 0, [], [])
+ _sre.compile({}, 0, [], 0, [], [], 0)
+ with self.assertRaises(RuntimeError):
+ # invalid repeat_count -1
+ _sre.compile("abc", 0, [1], 0, {}, (), -1)
def test_search_dot_unicode(self):
self.assertTrue(re.search("123.*-", '123abc-'))
@@ -2334,6 +2337,27 @@ POSSESSIVE_REPEAT 0 1
14. SUCCESS
''')
+ def test_repeat_index(self):
+ self.assertEqual(get_debug_out(r'(?:ab)*?(?:cd)*'), '''\
+MIN_REPEAT 0 MAXREPEAT
+ LITERAL 97
+ LITERAL 98
+MAX_REPEAT 0 MAXREPEAT
+ LITERAL 99
+ LITERAL 100
+
+ 0. INFO 4 0b0 0 MAXREPEAT (to 5)
+ 5: REPEAT 8 0 MAXREPEAT 0 (to 14)
+10. LITERAL 0x61 ('a')
+12. LITERAL 0x62 ('b')
+14: MIN_UNTIL
+15. REPEAT 8 0 MAXREPEAT 1 (to 24)
+20. LITERAL 0x63 ('c')
+22. LITERAL 0x64 ('d')
+24: MAX_UNTIL
+25. SUCCESS
+''')
+
class PatternReprTests(unittest.TestCase):
def check(self, pattern, expected):