From fee08a6d3b928032b10cca52ac907776b744b26e Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 24 Jul 2023 20:49:05 +0400 Subject: [PATCH] fix: properly handle character sets in globs (#24371) https://github.com/microsoft/playwright/issues/24316 --- packages/playwright-core/src/utils/glob.ts | 6 ++++++ tests/page/interception.spec.ts | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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 }) {