servo: Merge #11934 - Special-case setting location.hash to the empty string (from jdm:navigatefragment); r=emilio
authorJosh Matthews <josh@joshmatthews.net>
Wed, 29 Jun 2016 17:39:58 -0500
changeset 339159 817b20461b3c17b37762b4a852228d41fcc74f14
parent 339158 dc8cc3ec4670f4842b57d095f18c02ef7d00e8bb
child 339160 4539fc919dd83fac16e578ca5445a8dac78dfaa1
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
servo: Merge #11934 - Special-case setting location.hash to the empty string (from jdm:navigatefragment); r=emilio This avoids endless redirect loops on facebook and makes us compliant with https://github.com/whatwg/html/pull/1318. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #10952 - [X] There are tests for these changes OR Source-Repo: https://github.com/servo/servo Source-Revision: e30b288ed638f1903d30c8c5402b93b77b76b7b4
servo/components/script/dom/location.rs
--- a/servo/components/script/dom/location.rs
+++ b/servo/components/script/dom/location.rs
@@ -61,17 +61,20 @@ impl LocationMethods for Location {
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-location-hash
     fn Hash(&self) -> USVString {
         UrlHelper::Hash(&self.get_url())
     }
 
     // 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);
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-location-host
     fn Host(&self) -> USVString {
         UrlHelper::Host(&self.get_url())
     }