|
1 | 1 | from test.support import (gc_collect, bigmemtest, _2G,
|
2 | 2 | cpython_only, captured_stdout,
|
3 |
| - check_disallow_instantiation, is_emscripten, is_wasi) |
| 3 | + check_disallow_instantiation, is_emscripten, is_wasi, |
| 4 | + SHORT_TIMEOUT) |
4 | 5 | import locale
|
5 | 6 | import re
|
6 | 7 | import string
|
|
11 | 12 | from re import Scanner
|
12 | 13 | from weakref import proxy
|
13 | 14 |
|
| 15 | +# some platforms lack working multiprocessing |
| 16 | +try: |
| 17 | + import _multiprocessing |
| 18 | +except ImportError: |
| 19 | + multiprocessing = None |
| 20 | +else: |
| 21 | + import multiprocessing |
| 22 | + |
14 | 23 | # Misc tests from Tim Peters' re.doc
|
15 | 24 |
|
16 | 25 | # WARNING: Don't change details in these tests if you don't know
|
@@ -2407,6 +2416,26 @@ def test_template_function_and_flag_is_deprecated(self):
|
2407 | 2416 | self.assertTrue(template_re1.match('ahoy'))
|
2408 | 2417 | self.assertFalse(template_re1.match('nope'))
|
2409 | 2418 |
|
| 2419 | + @unittest.skipIf(multiprocessing is None, 'test requires multiprocessing') |
| 2420 | + def test_regression_gh94675(self): |
| 2421 | + pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*' |
| 2422 | + r'((/[^/\[\n]*(([^\n]|(\[\n]*(]*)*\]))' |
| 2423 | + r'[^/\[]*)*/))((((//[^\n]*)?[\n])' |
| 2424 | + r'([\000-\040]|(/\*[^*]*\*+' |
| 2425 | + r'([^/*]\*+)*/))*)+(?=[^\000-\040);\]}]))') |
| 2426 | + input_js = '''a(function() { |
| 2427 | + /////////////////////////////////////////////////////////////////// |
| 2428 | + });''' |
| 2429 | + p = multiprocessing.Process(target=pattern.sub, args=('', input_js)) |
| 2430 | + p.start() |
| 2431 | + p.join(SHORT_TIMEOUT) |
| 2432 | + try: |
| 2433 | + self.assertFalse(p.is_alive(), 'pattern.sub() timed out') |
| 2434 | + finally: |
| 2435 | + if p.is_alive(): |
| 2436 | + p.terminate() |
| 2437 | + p.join() |
| 2438 | + |
2410 | 2439 |
|
2411 | 2440 | def get_debug_out(pat):
|
2412 | 2441 | with captured_stdout() as out:
|
|
0 commit comments