Skip to content

Commit 895523d

Browse files
committed
impl 37996
1 parent 558941c commit 895523d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

playwright/_impl/_glob.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ def glob_to_regex_pattern(glob: str) -> str:
2828
tokens.append("\\" + char if char in escaped_chars else char)
2929
i += 1
3030
elif c == "*":
31+
char_before = glob[i - 1] if i > 0 else None
3132
star_count = 1
3233
while i + 1 < len(glob) and glob[i + 1] == "*":
3334
star_count += 1
3435
i += 1
3536
if star_count > 1:
36-
tokens.append("(.*)")
37+
char_after = glob[i + 1] if i + 1 < len(glob) else None
38+
if char_after == "/":
39+
if char_before == "/":
40+
tokens.append("((.+/)|)")
41+
else:
42+
tokens.append("(.*/)")
43+
i += 1
44+
else:
45+
tokens.append("(.*)")
3746
else:
3847
tokens.append("([^/]*)")
3948
else:

tests/async/test_page_route.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,10 @@ def glob_to_regex(pattern: str) -> re.Pattern:
10831083
"http://localhost:3000/signin-oidcnice"
10841084
)
10851085

1086+
assert glob_to_regex("**/*.js").match("/foo.js")
1087+
assert not glob_to_regex("asd/**.js").match("/foo.js")
1088+
assert not glob_to_regex("**/*.js").match("bar_foo.js")
1089+
10861090
# range [] is NOT supported
10871091
assert glob_to_regex("**/api/v[0-9]").fullmatch("http://example.com/api/v[0-9]")
10881092
assert not glob_to_regex("**/api/v[0-9]").fullmatch(
@@ -1174,6 +1178,10 @@ def glob_to_regex(pattern: str) -> re.Pattern:
11741178
assert url_matches("http://first.host/", "http://second.host/foo", "**/foo")
11751179
assert url_matches("http://playwright.dev/", "http://localhost/", "*//localhost/")
11761180

1181+
# /**/ should match /.
1182+
assert url_matches(None, "https://foo/bar.js", "https://foo/**/bar.js")
1183+
assert url_matches(None, "https://foo/bar.js", "https://foo/**/**/bar.js")
1184+
11771185
custom_prefixes = ["about", "data", "chrome", "edge", "file"]
11781186
for prefix in custom_prefixes:
11791187
assert url_matches(

0 commit comments

Comments
 (0)