Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: properly handle character sets in globs (#24371)

Andrey Lushnikovfee08a6d3b92
diff --git a/packages/playwright-core/src/utils/glob.ts b/packages/playwright-core/src/utils/glob.ts
index ae9a46b645..b464fc9a24 100644
--- a/packages/playwright-core/src/utils/glob.ts
+++ b/packages/playwright-core/src/utils/glob.ts
@@ -51,6 +51,12 @@ export function globToRegex(glob: string): RegExp {
case '?':
tokens.push('.');
break;
+ case '[':
+ tokens.push('[');
+ break;
+ case ']':
+ tokens.push(']');
+ break;
case '{':
inGroup = true;
tokens.push('(');
diff --git a/tests/page/interception.spec.ts b/tests/page/interception.spec.ts
index 9c73c0f31b..140346de69 100644
--- a/tests/page/interception.spec.ts
+++ b/tests/page/interception.spec.ts
@@ -91,12 +91,14 @@ it('should work with glob', async () => {
expect(globToRegex('http://localhost:3000/signin-oidc*').test('http://localhost:3000/signin-oidc/foo')).toBeFalsy();
expect(globToRegex('http://localhost:3000/signin-oidc*').test('http://localhost:3000/signin-oidcnice')).toBeTruthy();
+ 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();
+
expect(globToRegex('\\?')).toEqual(/^\?$/);
expect(globToRegex('\\')).toEqual(/^\\$/);
expect(globToRegex('\\\\')).toEqual(/^\\$/);
expect(globToRegex('\\[')).toEqual(/^\[$/);
- expect(globToRegex('[')).toEqual(/^\[$/);
- expect(globToRegex('$^+.\\*()|\\?\\{\\}[]')).toEqual(/^\$\^\+\.\*\(\)\|\?\{\}\[\]$/);
+ expect(globToRegex('[a-z]')).toEqual(/^[a-z]$/);
+ expect(globToRegex('$^+.\\*()|\\?\\{\\}\\[\\]')).toEqual(/^\$\^\+\.\*\(\)\|\?\{\}\[\]$/);
});
it('should intercept network activity from worker', async function({ page, server, isAndroid, browserName, browserMajorVersion }) {