Skip to content

Commit

Permalink
fix: properly handle character sets in globs
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Jul 24, 2023
1 parent b93b2a7 commit d4f81e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/playwright-core/src/utils/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('(');
Expand Down
6 changes: 4 additions & 2 deletions tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down

0 comments on commit d4f81e4

Please sign in to comment.