Skip to content

Commit 53c4ae2

Browse files
jellymartinpitt
authored andcommitted
lib: cockpit: drop old Mozilla window.location.hash hack
Firefox used to give a different value depending on the location hash when using `window.location.hash` and `window.location.href` with for example `#abc%21abc`. This is now fixed and in all browsers the following is always true: window.location.hash.slice(1) == window.location.href.split('#')[1] Which proves this is now fixed in Firefox.
1 parent 1d19a41 commit 53c4ae2

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

pkg/lib/cockpit.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,18 +1119,8 @@ function factory() {
11191119
* Cockpit location
11201120
*/
11211121

1122-
/* HACK: Mozilla will unescape 'window.location.hash' before returning
1123-
* it, which is broken.
1124-
*
1125-
* https://bugzilla.mozilla.org/show_bug.cgi?id=135309
1126-
*/
1127-
11281122
let last_loc = null;
11291123

1130-
function get_window_location_hash() {
1131-
return (window.location.href.split('#')[1] || '');
1132-
}
1133-
11341124
function Location() {
11351125
const self = this;
11361126
const application = cockpit.transport.application();
@@ -1145,7 +1135,7 @@ function factory() {
11451135
self.url_root = self.url_root + application.replace("cockpit+", '');
11461136
}
11471137

1148-
const href = get_window_location_hash();
1138+
const href = window.location.hash.slice(1);
11491139
const options = { };
11501140
self.path = decode(href, options);
11511141

@@ -1308,7 +1298,7 @@ function factory() {
13081298
Object.defineProperty(cockpit, "location", {
13091299
enumerable: true,
13101300
get: function() {
1311-
if (!last_loc || last_loc.href !== get_window_location_hash())
1301+
if (!last_loc || last_loc.href !== window.location.hash.slice(1))
13121302
last_loc = new Location();
13131303
return last_loc;
13141304
},
@@ -1319,9 +1309,7 @@ function factory() {
13191309

13201310
window.addEventListener("hashchange", function() {
13211311
last_loc = null;
1322-
let hash = window.location.hash;
1323-
if (hash.indexOf("#") === 0)
1324-
hash = hash.substring(1);
1312+
const hash = window.location.hash.slice(1);
13251313
cockpit.hint("location", { hash });
13261314
cockpit.dispatchEvent("locationchanged");
13271315
});

0 commit comments

Comments
 (0)