Skip to content

Commit

Permalink
updated to not read location.hash directly. Ran build.
Browse files Browse the repository at this point in the history
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 .
  • Loading branch information
Noah Feldman committed Sep 27, 2014
1 parent 892cc61 commit 0d55ec9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
25 changes: 16 additions & 9 deletions build/director.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@


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

(function (exports) {
Expand All @@ -17,19 +17,26 @@

var dloc = document.location;

function getHash() {
var hash = dloc.href.split("#")[1] || '';
if (hash !== '') { hash = '#' + hash }
return hash;
}

function dlocHashEmpty() {
// Non-IE browsers return '' when the address bar shows '#'; Director's logic
// assumes both mean empty.
return dloc.hash === '' || dloc.hash === '#';
var hash = getHash();
return hash === '' || hash === '#';
}

var listener = {
mode: 'modern',
hash: dloc.hash,
hash: getHash(),
history: false,

check: function () {
var h = dloc.hash;
var h = getHash();
if (h != this.hash) {
this.hash = h;
this.onHashChanged();
Expand Down Expand Up @@ -150,7 +157,7 @@ var listener = {
syncHash: function () {
// IE support...
var s = this._hash;
if (s != dloc.hash) {
if (s != getHash()) {
dloc.hash = s;
}
return this;
Expand Down Expand Up @@ -191,11 +198,11 @@ Router.prototype.init = function (r) {
if (dlocHashEmpty() && r) {
dloc.hash = r;
} else if (!dlocHashEmpty()) {
self.dispatch('on', '/' + dloc.hash.replace(/^(#\/|#|\/)/, ''));
self.dispatch('on', '/' + getHash().replace(/^(#\/|#|\/)/, ''));
}
}
else {
var routeTo = dlocHashEmpty() && r ? r : !dlocHashEmpty() ? dloc.hash.replace(/^#/, '') : null;
var routeTo = dlocHashEmpty() && r ? r : !dlocHashEmpty() ? getHash().replace(/^#/, '') : null;
if (routeTo) {
window.history.replaceState({}, document.title, routeTo);
}
Expand All @@ -211,7 +218,7 @@ Router.prototype.init = function (r) {
};

Router.prototype.explode = function () {
var v = this.history === true ? this.getPath() : dloc.hash;
var v = this.history === true ? this.getPath() : getHash();
if (v.charAt(1) === '/') { v=v.slice(1) }
return v.slice(1, v.length).split("/");
};
Expand Down
Loading

0 comments on commit 0d55ec9

Please sign in to comment.