From b747589286ad5e6da06208023d4f385a3dd0af03 Mon Sep 17 00:00:00 2001 From: lumiscosity Date: Thu, 14 Aug 2025 14:49:07 +0200 Subject: [PATCH] script: Strip `javascript` URL scheme using `Position::AfterScheme` rather than `Position::BeforePath` (#38599) This makes the initial split match step 2 of https://html.spec.whatwg.org/multipage/browsing-the-web.html#evaluate-a-javascript%3A-url. Testing: Covered by WPT tests. Fixes: #38547 --------- Signed-off-by: lumiscosity --- components/script/script_thread.rs | 2 +- tests/wpt/meta/MANIFEST.json | 2 +- tests/wpt/meta/url/javascript-urls.window.js.ini | 4 ---- tests/wpt/tests/url/javascript-urls.window.js | 6 ++++++ 4 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 tests/wpt/meta/url/javascript-urls.window.js.ini diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index e101befdb55..27041edf8d7 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -3592,7 +3592,7 @@ impl ScriptThread { // Start with the scheme data of the parsed URL; // append question mark and query component, if any; // append number sign and fragment component if any. - let encoded = &load_data.url.clone()[Position::BeforePath..]; + let encoded = &load_data.url[Position::AfterScheme..][1..]; // Percent-decode (8.) and UTF-8 decode (9.) let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy(); diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 4825ae0d957..d9ea56030df 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -835815,7 +835815,7 @@ ] ], "javascript-urls.window.js": [ - "4f617beca17082dc8459acb73bca781900170593", + "3e3a53003dde5fae29ced12ce9f2c26c7520a87c", [ "url/javascript-urls.window.html", {} diff --git a/tests/wpt/meta/url/javascript-urls.window.js.ini b/tests/wpt/meta/url/javascript-urls.window.js.ini deleted file mode 100644 index d75425614d2..00000000000 --- a/tests/wpt/meta/url/javascript-urls.window.js.ini +++ /dev/null @@ -1,4 +0,0 @@ -[javascript-urls.window.html] - expected: ERROR - [javascript: URL without an opaque path] - expected: FAIL diff --git a/tests/wpt/tests/url/javascript-urls.window.js b/tests/wpt/tests/url/javascript-urls.window.js index 4f617beca17..3e3a53003dd 100644 --- a/tests/wpt/tests/url/javascript-urls.window.js +++ b/tests/wpt/tests/url/javascript-urls.window.js @@ -19,6 +19,12 @@ "property": "shouldNotExistB", "expected": undefined }, + { + "description": "javascript: URL with extra slashes at the start", + "input": "javascript:///globalThis.shouldNotExistC=1", + "property": "shouldNotExistC", + "expected": undefined + }, { "description": "javascript: URL without an opaque path", "input": "javascript://host/1%0a//../0/;globalThis.shouldBeOne=1;/%0aglobalThis.shouldBeOne=2;/..///",