mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(unroute): do not compare regexp instances (#23101)
References #23092.
This commit is contained in:
parent
f1e0aed03c
commit
be7984bdc9
@ -28,7 +28,7 @@ import { Events } from './events';
|
||||
import { TimeoutSettings } from '../common/timeoutSettings';
|
||||
import { Waiter } from './waiter';
|
||||
import type { URLMatch, Headers, WaitForEventOptions, BrowserContextOptions, StorageState, LaunchOptions } from './types';
|
||||
import { headersObjectToArray, isRegExp, isString } from '../utils';
|
||||
import { headersObjectToArray, isRegExp, isString, urlMatchesEqual } from '../utils';
|
||||
import { mkdirIfNeeded } from '../utils/fileUtils';
|
||||
import type * as api from '../../types/types';
|
||||
import type * as structs from '../../types/structs';
|
||||
@ -316,7 +316,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
||||
}
|
||||
|
||||
async unroute(url: URLMatch, handler?: network.RouteHandlerCallback): Promise<void> {
|
||||
this._routes = this._routes.filter(route => route.url !== url || (handler && route.handler !== handler));
|
||||
this._routes = this._routes.filter(route => !urlMatchesEqual(route.url, url) || (handler && route.handler !== handler));
|
||||
await this._updateInterceptionPatterns();
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ import { urlMatches } from '../utils/network';
|
||||
import { TimeoutSettings } from '../common/timeoutSettings';
|
||||
import type * as channels from '@protocol/channels';
|
||||
import { parseError, serializeError } from '../protocol/serializers';
|
||||
import { assert, headersObjectToArray, isObject, isRegExp, isString, ScopedRace } from '../utils';
|
||||
import { assert, headersObjectToArray, isObject, isRegExp, isString, ScopedRace, urlMatchesEqual } from '../utils';
|
||||
import { mkdirIfNeeded } from '../utils/fileUtils';
|
||||
import { Accessibility } from './accessibility';
|
||||
import { Artifact } from './artifact';
|
||||
@ -458,7 +458,7 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
|
||||
}
|
||||
|
||||
async unroute(url: URLMatch, handler?: RouteHandlerCallback): Promise<void> {
|
||||
this._routes = this._routes.filter(route => route.url !== url || (handler && route.handler !== handler));
|
||||
this._routes = this._routes.filter(route => !urlMatchesEqual(route.url, url) || (handler && route.handler !== handler));
|
||||
await this._updateInterceptionPatterns();
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,12 @@ export function fetchData(params: HTTPRequestParams, onError?: (params: HTTPRequ
|
||||
});
|
||||
}
|
||||
|
||||
export function urlMatchesEqual(match1: URLMatch, match2: URLMatch) {
|
||||
if (isRegExp(match1) && isRegExp(match2))
|
||||
return match1.source === match2.source && match1.flags === match2.flags;
|
||||
return match1 === match2;
|
||||
}
|
||||
|
||||
export function urlMatches(baseURL: string | undefined, urlString: string, match: URLMatch | undefined): boolean {
|
||||
if (match === undefined || match === '')
|
||||
return true;
|
||||
|
@ -61,12 +61,12 @@ it('should unroute', async ({ browser, server }) => {
|
||||
intercepted.push(4);
|
||||
route.fallback();
|
||||
};
|
||||
await context.route('**/empty.html', handler4);
|
||||
await context.route(/empty.html/, handler4);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(intercepted).toEqual([4, 3, 2, 1]);
|
||||
|
||||
intercepted = [];
|
||||
await context.unroute('**/empty.html', handler4);
|
||||
await context.unroute(/empty.html/, handler4);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(intercepted).toEqual([3, 2, 1]);
|
||||
|
||||
|
@ -57,12 +57,12 @@ it('should unroute', async ({ page, server }) => {
|
||||
intercepted.push(4);
|
||||
route.fallback();
|
||||
};
|
||||
await page.route('**/empty.html', handler4);
|
||||
await page.route(/empty.html/, handler4);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(intercepted).toEqual([4, 3, 2, 1]);
|
||||
|
||||
intercepted = [];
|
||||
await page.unroute('**/empty.html', handler4);
|
||||
await page.unroute(/empty.html/, handler4);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(intercepted).toEqual([3, 2, 1]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user