Skip to content

Commit 0d55ec9

Browse files
author
Noah Feldman
committed
updated to not read location.hash directly. Ran build.
Firefox decodes any uri encoded values in location.hash when accessed directly. To safely use uri encoded URI as route parameters, we cannot read from location.hash .
1 parent 892cc61 commit 0d55ec9

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

build/director.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22

33
//
4-
// Generated on Wed Jun 25 2014 00:16:13 GMT-0700 (PDT) by Nodejitsu, Inc (Using Codesurgeon).
5-
// Version 1.2.4
4+
// Generated on Fri Sep 26 2014 20:19:31 GMT-0400 (EDT) by Nodejitsu, Inc (Using Codesurgeon).
5+
// Version 1.2.5
66
//
77

88
(function (exports) {
@@ -17,19 +17,26 @@
1717

1818
var dloc = document.location;
1919

20+
function getHash() {
21+
var hash = dloc.href.split("#")[1] || '';
22+
if (hash !== '') { hash = '#' + hash }
23+
return hash;
24+
}
25+
2026
function dlocHashEmpty() {
2127
// Non-IE browsers return '' when the address bar shows '#'; Director's logic
2228
// assumes both mean empty.
23-
return dloc.hash === '' || dloc.hash === '#';
29+
var hash = getHash();
30+
return hash === '' || hash === '#';
2431
}
2532

2633
var listener = {
2734
mode: 'modern',
28-
hash: dloc.hash,
35+
hash: getHash(),
2936
history: false,
3037

3138
check: function () {
32-
var h = dloc.hash;
39+
var h = getHash();
3340
if (h != this.hash) {
3441
this.hash = h;
3542
this.onHashChanged();
@@ -150,7 +157,7 @@ var listener = {
150157
syncHash: function () {
151158
// IE support...
152159
var s = this._hash;
153-
if (s != dloc.hash) {
160+
if (s != getHash()) {
154161
dloc.hash = s;
155162
}
156163
return this;
@@ -191,11 +198,11 @@ Router.prototype.init = function (r) {
191198
if (dlocHashEmpty() && r) {
192199
dloc.hash = r;
193200
} else if (!dlocHashEmpty()) {
194-
self.dispatch('on', '/' + dloc.hash.replace(/^(#\/|#|\/)/, ''));
201+
self.dispatch('on', '/' + getHash().replace(/^(#\/|#|\/)/, ''));
195202
}
196203
}
197204
else {
198-
var routeTo = dlocHashEmpty() && r ? r : !dlocHashEmpty() ? dloc.hash.replace(/^#/, '') : null;
205+
var routeTo = dlocHashEmpty() && r ? r : !dlocHashEmpty() ? getHash().replace(/^#/, '') : null;
199206
if (routeTo) {
200207
window.history.replaceState({}, document.title, routeTo);
201208
}
@@ -211,7 +218,7 @@ Router.prototype.init = function (r) {
211218
};
212219

213220
Router.prototype.explode = function () {
214-
var v = this.history === true ? this.getPath() : dloc.hash;
221+
var v = this.history === true ? this.getPath() : getHash();
215222
if (v.charAt(1) === '/') { v=v.slice(1) }
216223
return v.slice(1, v.length).split("/");
217224
};

0 commit comments

Comments
 (0)