Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-94675: Add a regression test for rjsmin re slowdown #94685

Merged
merged 6 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion Lib/test/test_re.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from test.support import (gc_collect, bigmemtest, _2G,
cpython_only, captured_stdout,
check_disallow_instantiation, is_emscripten, is_wasi)
check_disallow_instantiation, is_emscripten, is_wasi,
SHORT_TIMEOUT)
import locale
import re
import string
Expand All @@ -11,6 +12,14 @@
from re import Scanner
from weakref import proxy

# some platforms lack working multiprocessing
try:
import _multiprocessing
except ImportError:
multiprocessing = None
else:
import multiprocessing

# Misc tests from Tim Peters' re.doc

# WARNING: Don't change details in these tests if you don't know
Expand Down Expand Up @@ -2407,6 +2416,26 @@ def test_template_function_and_flag_is_deprecated(self):
self.assertTrue(template_re1.match('ahoy'))
self.assertFalse(template_re1.match('nope'))

@unittest.skipIf(multiprocessing is None, 'test requires multiprocessing')
def test_regression_gh94675(self):
pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*'
r'((/[^/\[\n]*(([^\n]|(\[\n]*(]*)*\]))'
r'[^/\[]*)*/))((((//[^\n]*)?[\n])'
r'([\000-\040]|(/\*[^*]*\*+'
r'([^/*]\*+)*/))*)+(?=[^\000-\040);\]}]))')
input_js = '''a(function() {
///////////////////////////////////////////////////////////////////
});'''
p = multiprocessing.Process(target=pattern.sub, args=('', input_js))
p.start()
p.join(SHORT_TIMEOUT)
try:
self.assertFalse(p.is_alive(), 'pattern.sub() timed out')
finally:
if p.is_alive():
p.terminate()
p.join()


def get_debug_out(pat):
with captured_stdout() as out:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a regression test for :mod:`re` exponentional slowdown when using rjsmin.