diff options
4 files changed, 45 insertions, 2 deletions
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 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Navigating to the same URL with an empty fragment aborts the navigation</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<iframe src="empty_fragment_iframe.html"></iframe> +<script> +// If the navigation were not aborted, we would expect multiple load events +// as the page continually reloads itself. +async_test(function(t) { + var count = 0; + var iframe = document.querySelector('iframe'); + iframe.onload = t.step_func(function() { + count++; + }); + window.child_succeeded = t.step_func_done(function() { + assert_equals(count, 1); + }); +}); +</script> 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 @@ +<script> +var timeout; +onload = function() { + location.hash = ""; + timeout = setTimeout(function() { parent.child_succeeded() }, 2000); +}; + +onbeforeunload = function() { + clearTimeout(timeout); +} +</script> |