diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index f7bb765651d6..fce0567f31c8 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1833,24 +1833,25 @@ impl ScriptThread { /// The entry point for content to notify that a new load has been requested /// for the given pipeline (specifically the "navigate" algorithm). fn handle_navigate(&self, pipeline_id: PipelineId, subpage_id: Option, load_data: LoadData) { - // Step 8. + // Step 6. { let nurl = &load_data.url; - if let Some(fragment) = nurl.fragment() { - let context = get_browsing_context(&self.root_browsing_context(), pipeline_id); - let document = context.active_document(); - let document = document.r(); - let url = document.url(); - if &url[..Position::AfterQuery] == &nurl[..Position::AfterQuery] && - load_data.method == Method::Get { - match document.find_fragment_node(fragment) { - Some(ref node) => { - self.scroll_fragment_point(pipeline_id, node.r()); - } - None => {} + let context = get_browsing_context(&self.root_browsing_context(), pipeline_id); + let document = context.active_document(); + let document = document.r(); + let url = document.url(); + if &url[..Position::AfterQuery] == &nurl[..Position::AfterQuery] && + load_data.method == Method::Get { + if let Some(fragment) = nurl.fragment() { + if let Some(ref node) = document.find_fragment_node(fragment) { + self.scroll_fragment_point(pipeline_id, node.r()); } - return; } + // TODO: Revisit this return statement when a decission is taken + // in https://github.com/whatwg/html/issues/1177. + // + // See #10954 for discussion and background. + return; } } diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 91b533bcbfff..bd0e05d5b463 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -35938,6 +35938,12 @@ "deleted_reftests": {}, "items": { "testharness": { + "html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html": [ + { + "path": "html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html", + "url": "/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html" + } + ], "html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_attribute-getter-setter.html": [ { "path": "html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_attribute-getter-setter.html", diff --git a/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html b/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html new file mode 100644 index 000000000000..18a6f84c9f59 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html @@ -0,0 +1,20 @@ + + +Navigating to the same URL with an empty fragment aborts the navigation + + + + diff --git a/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment_iframe.html b/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment_iframe.html new file mode 100644 index 000000000000..26b28a0d7dcb --- /dev/null +++ b/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment_iframe.html @@ -0,0 +1,11 @@ +