Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 44cf34b

Browse files
committed
Cleaner fix for the cross-browser history bug
I haven't found a better fix (than changing checkUrl) yet, however here's an improved version of the change, it's a lot cleaner and it does work. It doesn't have all that character replacement nonsense, and it's probably faster.
1 parent b4c36a0 commit 44cf34b

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

Diff for: src/plugins/js/history.js

+4-25
Original file line numberDiff line numberDiff line change
@@ -174,48 +174,27 @@ define(['durandal/system', 'jquery'], function (system, $) {
174174
history.active = false;
175175
};
176176

177-
/**
178-
* Cleans a given URL fragment so that history.fragment can be safely compared with history.getHash
179-
* The characters replaced are: `~!*()'-._`
180-
* Based on http://www.justarrangingbits.org/firefox-magic-decoding-address-bar/index.html
181-
* @method cleanFragment
182-
* @return {string} Returns a string with normalized characters.
183-
*/
184-
function cleanFragment(s) {
185-
return (s || "")
186-
.replace(/~/g, "%7E")
187-
.replace(/!/g, "%21")
188-
.replace(/\*/g, "%2A")
189-
.replace(/\(/g, "%28")
190-
.replace(/\)/g, "%29")
191-
.replace(/'/g, "%27")
192-
.replace(/-/g, "%2D")
193-
.replace(/\./g, "%2E")
194-
.replace(/_/g, "%5F");
195-
}
196-
197177
/**
198178
* Checks the current URL to see if it has changed, and if it has, calls `loadUrl`, normalizing across the hidden iframe.
199179
* @method checkUrl
200180
* @return {boolean} Returns true/false from loading the url.
201181
*/
202182
history.checkUrl = function() {
203183
var current = history.getFragment();
204-
var currentFragment = cleanFragment(current);
205-
var historyFragment = cleanFragment(history.fragment);
184+
var currentIsFragment = decodeURIComponent(current) === decodeURIComponent(history.fragment);
206185

207-
if (currentFragment === historyFragment && history.iframe) {
186+
if (currentIsFragment && history.iframe) {
208187
current = history.getFragment(history.getHash(history.iframe));
209188
}
210189

211-
if (currentFragment === historyFragment) {
190+
if (currentIsFragment) {
212191
return false;
213192
}
214193

215194
if (history.iframe) {
216195
history.navigate(current, false);
217196
}
218-
197+
219198
history.loadUrl();
220199
};
221200

0 commit comments

Comments
 (0)