From be176709f6d0700da0261e4551725a2612c82d45 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Fri, 16 May 2014 18:29:21 -0400 Subject: [PATCH 1/2] Handle incorrect hash/search values in IE6. In IE6, the hash/search value will not be correct when the hash fragment contains '?'. --- backbone.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backbone.js b/backbone.js index 28e9e30e..10a40e4a 100644 --- a/backbone.js +++ b/backbone.js @@ -1419,7 +1419,12 @@ // Are we at the app root? atRoot: function() { var path = this.location.pathname.replace(/[^\/]$/, '$&/'); - return path === this.root && !this.location.search; + return path === this.root && !this.getSearch(); + }, + + getSearch: function() { + var match = this.location.href.replace(/#.*$/, '').match(/\?.+$/); + return match ? match[0] : ''; }, // Gets the true hash value. Cannot use location.hash directly due to bug @@ -1431,7 +1436,7 @@ // Get the pathname and search params, without the root. getPath: function() { - var path = decodeURI(this.location.pathname + this.location.search); + var path = decodeURI(this.location.pathname + this.getSearch()); var root = this.root.slice(0, -1); if (!path.indexOf(root)) path = path.slice(root.length); return path.slice(1); From 5573ef72caba989a44ed4094f584b6878fa65e03 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Sat, 17 May 2014 08:54:35 -0400 Subject: [PATCH 2/2] Add comment, remove anchors. --- backbone.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index 10a40e4a..5a2486bb 100644 --- a/backbone.js +++ b/backbone.js @@ -1422,8 +1422,10 @@ return path === this.root && !this.getSearch(); }, + // In IE6, the hash fragment and search params are incorrect if the + // fragment contains `?`. getSearch: function() { - var match = this.location.href.replace(/#.*$/, '').match(/\?.+$/); + var match = this.location.href.replace(/#.*/, '').match(/\?.+/); return match ? match[0] : ''; },