From c7c1538c065fb4f0c629380ac9b886fcf1b9a067 Mon Sep 17 00:00:00 2001 From: Divine Ikhuoria <64232397+Divuzki@users.noreply.github.com> Date: Sat, 28 Nov 2026 11:49:52 -0500 Subject: [PATCH] Match adjacent wildcards in extraction mappings --- babel/util.py | 2 +- tests/test_util.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/babel/util.py b/babel/util.py index a2bf728cc..1423e2978 100644 --- a/babel/util.py +++ b/babel/util.py @@ -194,7 +194,7 @@ def pathmatch(pattern: str, filename: str) -> bool: else: buf = [] - for idx, part in enumerate(re.split('([?*]+/?)', pattern)): + for idx, part in enumerate(re.split(r'((?:\*{1,2}|\?)/?)', pattern)): if idx % 2: buf.append(symbols[part]) elif part: diff --git a/tests/test_util.py b/tests/test_util.py index 3655f423a..3dd49f5d5 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -45,6 +45,20 @@ def test_pathmatch(): assert not util.pathmatch('./foo/**.py', 'blah/foo/bar/baz.py') +@pytest.mark.parametrize( + ("pattern", "filename", "expected"), + [ + ("locale/??/messages.py", "locale/en/messages.py", True), + ("locale/??/messages.py", "locale/eng/messages.py", False), + ("locale/??/messages.py", "locale/e/n/messages.py", False), + ("**/test_?*.py", "pkg/sub/test_ab.py", True), + ("**/test_*?.py", "test_ab.py", True), + ], +) +def test_pathmatch_adjacent_wildcards(pattern, filename, expected): + assert util.pathmatch(pattern, filename) is expected + + def test_fixed_zone_negative_offset(): assert util.FixedOffsetTimezone(-60).zone == 'Etc/GMT-60'