diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index 9fff2a45837..72361193aa3 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -66,7 +66,10 @@ impl LocationMethods for Location { } // https://html.spec.whatwg.org/multipage/#dom-location-hash - fn SetHash(&self, value: USVString) { + fn SetHash(&self, mut value: USVString) { + if value.0.is_empty() { + value = USVString("#".to_owned()); + } self.set_url_component(value, UrlHelper::SetHash); } diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 9dc86c4804d..1a4452832b9 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -36263,7 +36263,16 @@ "local_changes": { "deleted": [], "deleted_reftests": {}, - "items": {}, + "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" + } + ] + } + }, "reftest_nodes": {} }, "reftest_nodes": { 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 00000000000..18a6f84c9f5 --- /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 00000000000..26b28a0d7dc --- /dev/null +++ b/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment_iframe.html @@ -0,0 +1,11 @@ +