Skip to content

Commit 63f9899

Browse files
committed
gh-94675: Add a regression test for rjsmin re slowdown
1 parent e5b841a commit 63f9899

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Lib/test/test_re.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,21 @@ def test_template_function_and_flag_is_deprecated(self):
24072407
self.assertTrue(template_re1.match('ahoy'))
24082408
self.assertFalse(template_re1.match('nope'))
24092409

2410+
def test_regression_gh94675(self):
2411+
start = time.perf_counter()
2412+
pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*'
2413+
r'((/[^/\[\n]*(([^\n]|(\[\n]*(]*)*\]))'
2414+
r'[^/\[]*)*/))((((//[^\n]*)?[\n])'
2415+
r'([\000-\040]|(/\*[^*]*\*+'
2416+
r'([^/*]\*+)*/))*)+(?=[^\000-\040);\]}]))')
2417+
input_js = '''a(function() {
2418+
///////////////////////////////////////////////////////////////////
2419+
});'''
2420+
_ = pattern.sub('', input_js)
2421+
t = time.perf_counter() - start
2422+
# Without optimization it takes 0.017 second on my computer.
2423+
self.assertLess(t, 0.5)
2424+
24102425

24112426
def get_debug_out(pat):
24122427
with captured_stdout() as out:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a regreesion test for :mod:`re` exponencional slowdon when using rjsmin.

0 commit comments

Comments
 (0)