Skip to content

Commit 40e2096

Browse files
committed
cherry-pick(#24371): fix: properly handle character sets in globs
microsoft/playwright#24316
1 parent 4417b78 commit 40e2096

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/playwright-core/src/utils/glob.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export function globToRegex(glob: string): RegExp {
5151
case '?':
5252
tokens.push('.');
5353
break;
54+
case '[':
55+
tokens.push('[');
56+
break;
57+
case ']':
58+
tokens.push(']');
59+
break;
5460
case '{':
5561
inGroup = true;
5662
tokens.push('(');

tests/page/interception.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ it('should work with glob', async () => {
9191
expect(globToRegex('http://localhost:3000/signin-oidc*').test('http://localhost:3000/signin-oidc/foo')).toBeFalsy();
9292
expect(globToRegex('http://localhost:3000/signin-oidc*').test('http://localhost:3000/signin-oidcnice')).toBeTruthy();
9393

94+
expect(globToRegex('**/three-columns/settings.html?**id=[a-z]**').test('http://mydomain:8080/blah/blah/three-columns/settings.html?id=settings-e3c58efe-02e9-44b0-97ac-dd138100cf7c&blah')).toBeTruthy();
95+
9496
expect(globToRegex('\\?')).toEqual(/^\?$/);
9597
expect(globToRegex('\\')).toEqual(/^\\$/);
9698
expect(globToRegex('\\\\')).toEqual(/^\\$/);
9799
expect(globToRegex('\\[')).toEqual(/^\[$/);
98-
expect(globToRegex('[')).toEqual(/^\[$/);
99-
expect(globToRegex('$^+.\\*()|\\?\\{\\}[]')).toEqual(/^\$\^\+\.\*\(\)\|\?\{\}\[\]$/);
100+
expect(globToRegex('[a-z]')).toEqual(/^[a-z]$/);
101+
expect(globToRegex('$^+.\\*()|\\?\\{\\}\\[\\]')).toEqual(/^\$\^\+\.\*\(\)\|\?\{\}\[\]$/);
100102
});
101103

102104
it('should intercept network activity from worker', async function({ page, server, isAndroid, browserName, browserMajorVersion }) {

0 commit comments

Comments
 (0)