Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/isomorphic/urlMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ function deserializeURLPattern(v: ReturnType<typeof serializeURLPattern>): URLPa
if (typeof globalThis.URLPattern !== 'function')
return () => true;

// URLPattern does not expose ignoreCase, so match case-insensitively on the server
// to avoid false negatives. The client filters again with the original pattern.
// @ts-ignore URLPattern is not in @types/node yet
// eslint-disable-next-line no-restricted-globals
return new globalThis.URLPattern({
Expand All @@ -158,7 +160,7 @@ function deserializeURLPattern(v: ReturnType<typeof serializeURLPattern>): URLPa
protocol: v.protocol,
search: v.search,
username: v.username,
});
}, { ignoreCase: true });
}

export function deserializeURLMatch(match: { glob?: string, regexSource?: string, regexFlags?: string, urlPattern?: ReturnType<typeof serializeURLPattern> }): URLMatch {
Expand Down
20 changes: 20 additions & 0 deletions tests/library/browsercontext-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,23 @@ it('should fulfill popup main request using alias', async ({ page, server, isEle
]);
await expect(popup.locator('body')).toHaveText('hello');
});

it('should respect URLPattern ignoreCase', async ({ context, page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42918' });
it.skip(globalThis.URLPattern === undefined, 'URLPattern is not supported in this environment');

const intercepted: string[] = [];
// @ts-ignore URLPattern is not in @types/node yet
await context.route(new URLPattern(server.PREFIX + '/EMPTY.html', { ignoreCase: true }), route => {
intercepted.push('ignoreCase');
return route.fulfill({ body: 'mock' });
});
// @ts-ignore URLPattern is not in @types/node yet
await context.route(new URLPattern(server.PREFIX + '/EMPTY.html'), route => {
intercepted.push('caseSensitive');
return route.fulfill({ body: 'mock' });
});
const response = await page.goto(server.EMPTY_PAGE);
expect(await response!.text()).toBe('mock');
expect(intercepted).toEqual(['ignoreCase']);
});
20 changes: 20 additions & 0 deletions tests/page/page-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,3 +1138,23 @@ it('should be able to intercept every navigation to a page controlled by service
await page.goto(URL);
expect(interceptions).toBe(2);
});

it('should respect URLPattern ignoreCase', async ({ page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42918' });
it.skip(globalThis.URLPattern === undefined, 'URLPattern is not supported in this environment');

const intercepted: string[] = [];
// @ts-ignore URLPattern is not in @types/node yet
await page.route(new URLPattern(server.PREFIX + '/EMPTY.html', { ignoreCase: true }), route => {
intercepted.push('ignoreCase');
return route.fulfill({ body: 'mock' });
});
// @ts-ignore URLPattern is not in @types/node yet
await page.route(new URLPattern(server.PREFIX + '/EMPTY.html'), route => {
intercepted.push('caseSensitive');
return route.fulfill({ body: 'mock' });
});
const response = await page.goto(server.EMPTY_PAGE);
expect(await response!.text()).toBe('mock');
expect(intercepted).toEqual(['ignoreCase']);
});
Loading