From ed9f08eb6d68b572f76e517d95d84c7a00664a21 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov Date: Tue, 12 Mar 2024 17:03:14 +0100 Subject: [PATCH 1/2] fix: the pattern matching logic --- .../domains/network/NetworkProcessor.ts | 5 +++- .../domains/network/NetworkUtils.ts | 24 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/bidiMapper/domains/network/NetworkProcessor.ts b/src/bidiMapper/domains/network/NetworkProcessor.ts index 48dd590ac0..d169499966 100644 --- a/src/bidiMapper/domains/network/NetworkProcessor.ts +++ b/src/bidiMapper/domains/network/NetworkProcessor.ts @@ -310,7 +310,7 @@ export class NetworkProcessor { if (urlPattern.pathname) { urlPattern.pathname = unescapeURLPattern(urlPattern.pathname); if (urlPattern.pathname[0] !== '/') { - urlPattern.search = `/${urlPattern.search}`; + urlPattern.pathname = `/${urlPattern.pathname}`; } if ( urlPattern.pathname.includes('#') || @@ -318,7 +318,10 @@ export class NetworkProcessor { ) { throw new InvalidArgumentException('Forbidden characters'); } + } else if (urlPattern.pathname === '') { + urlPattern.pathname = '*'; } + if (urlPattern.search) { urlPattern.search = unescapeURLPattern(urlPattern.search); if (urlPattern.search[0] !== '?') { diff --git a/src/bidiMapper/domains/network/NetworkUtils.ts b/src/bidiMapper/domains/network/NetworkUtils.ts index f426fbd5d6..d45b6f4d1e 100644 --- a/src/bidiMapper/domains/network/NetworkUtils.ts +++ b/src/bidiMapper/domains/network/NetworkUtils.ts @@ -20,6 +20,7 @@ * @fileoverview Utility functions for the Network domain. */ import type {Protocol} from 'devtools-protocol'; +import type {URLPatternInit} from 'urlpattern-polyfill/dist/types.js'; import {InvalidArgumentException} from '../../../protocol/ErrorResponse.js'; import {Network, type Storage} from '../../../protocol/protocol.js'; @@ -253,12 +254,29 @@ export function isSpecialScheme(protocol: string): boolean { protocol.replace(/:$/, '') ); } + +type RequireStringPattern = Omit< + Required, + 'baseURL' | 'hash' | 'username' | 'password' +>; + /** Matches the given URLPattern against the given URL. */ export function matchUrlPattern( urlPattern: Network.UrlPattern, url: string | undefined ): boolean { - return new URLPattern( - urlPattern.type === 'string' ? urlPattern.pattern : urlPattern - ).test(url); + switch (urlPattern.type) { + case 'string': { + const pattern = new URLPattern(urlPattern.pattern); + return new URLPattern({ + protocol: pattern.protocol, + hostname: pattern.hostname, + port: pattern.port, + pathname: pattern.pathname, + search: pattern.search, + } satisfies RequireStringPattern).test(url); + } + case 'pattern': + return new URLPattern(urlPattern).test(url); + } } From e3b22d33140a4484936918d767d97d62b45b74a9 Mon Sep 17 00:00:00 2001 From: Lightning00Blade Date: Tue, 12 Mar 2024 16:15:15 +0000 Subject: [PATCH 2/2] Update WPT expectations Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../network/add_intercept/url_patterns.py.ini | 19 ++----------------- .../network/add_intercept/url_patterns.py.ini | 19 ++----------------- .../network/add_intercept/url_patterns.py.ini | 19 ++----------------- 3 files changed, 6 insertions(+), 51 deletions(-) diff --git a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini b/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini index b19752f0c1..dbe45e8580 100644 --- a/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini +++ b/wpt-metadata/chromedriver/headful/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini @@ -1,21 +1,6 @@ [url_patterns.py] - [test_pattern_patterns_matching[patterns22-https://{wpt_host}\]] - expected: FAIL - - [test_pattern_patterns_matching[patterns23-https://{wpt_host}/\]] - expected: FAIL - - [test_pattern_patterns_matching[patterns24-https://{wpt_host}/path\]] - expected: FAIL - - [test_string_patterns_matching[https://user:password@{wpt_host}/-https://{wpt_host}/\]] - expected: FAIL - - [test_string_patterns_matching[https://{wpt_host}/#ref-https://{wpt_host}/\]] - expected: FAIL - - [test_string_patterns_matching[https://{wpt_host}/#ref1-https://{wpt_host}/#ref2\]] + [test_string_patterns_not_matching[https://{wpt_host}/??-https://{wpt_host}/?\]] expected: FAIL - [test_string_patterns_not_matching[https://{wpt_host}/??-https://{wpt_host}/?\]] + [test_pattern_patterns_not_matching[pattern6-https://{wpt_host}/path\]] expected: FAIL diff --git a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini b/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini index b19752f0c1..dbe45e8580 100644 --- a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini +++ b/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini @@ -1,21 +1,6 @@ [url_patterns.py] - [test_pattern_patterns_matching[patterns22-https://{wpt_host}\]] - expected: FAIL - - [test_pattern_patterns_matching[patterns23-https://{wpt_host}/\]] - expected: FAIL - - [test_pattern_patterns_matching[patterns24-https://{wpt_host}/path\]] - expected: FAIL - - [test_string_patterns_matching[https://user:password@{wpt_host}/-https://{wpt_host}/\]] - expected: FAIL - - [test_string_patterns_matching[https://{wpt_host}/#ref-https://{wpt_host}/\]] - expected: FAIL - - [test_string_patterns_matching[https://{wpt_host}/#ref1-https://{wpt_host}/#ref2\]] + [test_string_patterns_not_matching[https://{wpt_host}/??-https://{wpt_host}/?\]] expected: FAIL - [test_string_patterns_not_matching[https://{wpt_host}/??-https://{wpt_host}/?\]] + [test_pattern_patterns_not_matching[pattern6-https://{wpt_host}/path\]] expected: FAIL diff --git a/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini b/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini index b19752f0c1..dbe45e8580 100644 --- a/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini +++ b/wpt-metadata/mapper/headless/webdriver/tests/bidi/network/add_intercept/url_patterns.py.ini @@ -1,21 +1,6 @@ [url_patterns.py] - [test_pattern_patterns_matching[patterns22-https://{wpt_host}\]] - expected: FAIL - - [test_pattern_patterns_matching[patterns23-https://{wpt_host}/\]] - expected: FAIL - - [test_pattern_patterns_matching[patterns24-https://{wpt_host}/path\]] - expected: FAIL - - [test_string_patterns_matching[https://user:password@{wpt_host}/-https://{wpt_host}/\]] - expected: FAIL - - [test_string_patterns_matching[https://{wpt_host}/#ref-https://{wpt_host}/\]] - expected: FAIL - - [test_string_patterns_matching[https://{wpt_host}/#ref1-https://{wpt_host}/#ref2\]] + [test_string_patterns_not_matching[https://{wpt_host}/??-https://{wpt_host}/?\]] expected: FAIL - [test_string_patterns_not_matching[https://{wpt_host}/??-https://{wpt_host}/?\]] + [test_pattern_patterns_not_matching[pattern6-https://{wpt_host}/path\]] expected: FAIL