From 6ec6e0c9ec5a9f0a01fe573cfc76fb26986fbd18 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 9 Mar 2022 13:22:14 +0200 Subject: [PATCH] Replace freezing regex with plain text operations. The regex in question causes Python's regex parser to freeze indefinitely in certain Python versions. That might be due to a bug or because the re does infinite backtracking and it just happened to work on earlier implementations. --- unittests/allplatformstests.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 665e0c62d..6efff6101 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -3376,9 +3376,21 @@ class AllPlatformTests(BasePlatformTests): ## Validate commands md_commands = {k for k,v in md_command_sections.items()} - help_output = self._run(self.meson_command + ['--help']) - help_commands = {c.strip() for c in re.findall(r'usage:(?:.+)?{((?:[a-z]+,*)+?)}', help_output, re.MULTILINE|re.DOTALL)[0].split(',')} + # Python's argument parser might put the command list to its own line. Or it might not. + self.assertTrue(help_output.startswith('usage: ')) + lines = help_output.split('\n') + line1 = lines[0] + line2 = lines[1] + if '{' in line1: + cmndline = line1 + else: + self.assertIn('{', line2) + cmndline = line2 + cmndstr = cmndline.split('{')[1] + self.assertIn('}', cmndstr) + help_commands = set(cmndstr.split('}')[0].split(',')) + self.assertTrue(len(help_commands) > 0, 'Must detect some command names.') self.assertEqual(md_commands | {'help'}, help_commands, f'Doc file: `{doc_path}`')