# HG changeset patch # User RhodeCode Admin # Date 2023-11-06 10:24:42 # Node ID 51a848c76291233402fb3e1f607ab383dbb7352d # Parent 76f12b0373ef063e756cbbe4a15029389829875d chore(regex): properly escape \d used in regexes diff --git a/rhodecode/tests/lib/test_helpers.py b/rhodecode/tests/lib/test_helpers.py --- a/rhodecode/tests/lib/test_helpers.py +++ b/rhodecode/tests/lib/test_helpers.py @@ -96,12 +96,12 @@ def test_format_binary(): @pytest.mark.parametrize('text_string, pattern, expected', [ ('No issue here', r'(?:#)(?P\d+)', []), - ('Fix #42', '(?:#)(?P\d+)', + ('Fix #42', r'(?:#)(?P\d+)', [{'url': 'https://r.io/{repo}/i/42', 'id': '42'}]), - ('Fix #42, #53', '(?:#)(?P\d+)', [ + ('Fix #42, #53', r'(?:#)(?P\d+)', [ {'url': 'https://r.io/{repo}/i/42', 'id': '42'}, {'url': 'https://r.io/{repo}/i/53', 'id': '53'}]), - ('Fix #42', '(?:#)?\d+)', []), # Broken regex + ('Fix #42', r'(?:#)?\d+)', []), # Broken regex ]) def test_extract_issues(backend, text_string, pattern, expected): repo = backend.create_repo() @@ -130,16 +130,16 @@ def test_extract_issues(backend, text_st @pytest.mark.parametrize('text_string, pattern, link_format, expected_text', [ - ('Fix #42', '(?:#)(?P\d+)', 'html', + ('Fix #42', r'(?:#)(?P\d+)', 'html', 'Fix #42'), - ('Fix #42', '(?:#)(?P\d+)', 'markdown', + ('Fix #42', r'(?:#)(?P\d+)', 'markdown', 'Fix [#42](https://r.io/{repo}/i/42)'), - ('Fix #42', '(?:#)(?P\d+)', 'rst', + ('Fix #42', r'(?:#)(?P\d+)', 'rst', 'Fix `#42 `_'), - ('Fix #42', '(?:#)?\d+)', 'html', + ('Fix #42', r'(?:#)?\d+)', 'html', 'Fix #42'), # Broken regex ]) def test_process_patterns_repo(backend, text_string, pattern, expected_text, link_format): @@ -165,9 +165,9 @@ def test_process_patterns_repo(backend, @pytest.mark.parametrize('text_string, pattern, expected_text', [ - ('Fix #42', '(?:#)(?P\d+)', + ('Fix #42', r'(?:#)(?P\d+)', 'Fix #42'), - ('Fix #42', '(?:#)?\d+)', + ('Fix #42', r'(?:#)?\d+)', 'Fix #42'), # Broken regex ]) def test_process_patterns_no_repo(text_string, pattern, expected_text):