diff --git a/components/script/script_task.rs b/components/script/script_task.rs index dda6faaa85b..773d43448c4 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -1671,10 +1671,32 @@ impl ScriptTask { let is_javascript = incomplete.url.scheme == "javascript"; let parse_input = if is_javascript { + use url::percent_encoding::percent_decode_to; + + // Turn javascript: URL into JS code to eval, according to the steps in + // https://html.spec.whatwg.org/multipage/#javascript-protocol let _ar = JSAutoRequest::new(self.get_cx()); - let evalstr = incomplete.url.non_relative_scheme_data().unwrap(); + let mut script_source_bytes = Vec::new(); + // Start with the scheme data of the parsed URL (5.), while percent-decoding (8.) + percent_decode_to(incomplete.url.non_relative_scheme_data().unwrap().as_bytes(), + &mut script_source_bytes); + // Append question mark and query component, if any (6.), while percent-decoding (8.) + if let Some(ref query) = incomplete.url.query { + script_source_bytes.push(b'?'); + percent_decode_to(query.as_bytes(), &mut script_source_bytes); + } + // Append number sign and fragment component if any (7.), while percent-decoding (8.) + if let Some(ref fragment) = incomplete.url.fragment { + script_source_bytes.push(b'#'); + percent_decode_to(fragment.as_bytes(), &mut script_source_bytes); + } + + // UTF-8 decode (9.) + let script_source = String::from_utf8_lossy(&script_source_bytes); + + // Script source is ready to be evaluated (11.) let mut jsval = RootedValue::new(self.get_cx(), UndefinedValue()); - window.evaluate_js_on_global_with_result(evalstr, jsval.handle_mut()); + window.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut()); let strval = DOMString::from_jsval(self.get_cx(), jsval.handle(), StringificationBehavior::Empty); strval.unwrap_or(DOMString::new()) diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index f279b5f318f..22cd43f2f37 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -29809,7 +29809,16 @@ }, "local_changes": { "deleted": [], - "items": {}, + "items": { + "testharness": { + "html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html": [ + { + "path": "html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html", + "url": "/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html" + } + ] + } + }, "reftest_nodes": {} }, "reftest_nodes": { diff --git a/tests/wpt/metadata/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html.ini b/tests/wpt/metadata/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html.ini new file mode 100644 index 00000000000..f95e9c54bbe --- /dev/null +++ b/tests/wpt/metadata/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html.ini @@ -0,0 +1,7 @@ +[javascript-url-query-fragment-components.html] + type: testharness + expected: OK + [iframes with javascript src] + expected: FAIL + + diff --git a/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html b/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html new file mode 100644 index 00000000000..9c18f109cd5 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-query-fragment-components.html @@ -0,0 +1,28 @@ + +