[Pkg-javascript-commits] [backbone] 183/281: Fixes #786 (and others) -- leading slashes should never be defined as routes, or passed to navigate ... so strip 'em out proactively.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:10 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.9.0
in repository backbone.

commit d5ff5e32f6a6f6ea643ff5e5a1172778f56f0b83
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Thu Jan 12 18:10:41 2012 -0500

    Fixes #786 (and others) -- leading slashes should never be defined as routes, or passed to navigate ... so strip 'em out proactively.
---
 backbone.js    | 10 +++++-----
 test/router.js |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/backbone.js b/backbone.js
index 5728749..a1b228b 100644
--- a/backbone.js
+++ b/backbone.js
@@ -704,8 +704,8 @@
     _.bindAll(this, 'checkUrl');
   };
 
-  // Cached regex for cleaning hashes.
-  var hashStrip = /^#/;
+  // Cached regex for cleaning leading hashes and slashes .
+  var routeStripper = /^[#\/]/;
 
   // Cached regex for detecting MSIE.
   var isExplorer = /msie [\w.]+/;
@@ -732,7 +732,7 @@
           fragment = window.location.hash;
         }
       }
-      fragment = decodeURIComponent(fragment.replace(hashStrip, ''));
+      fragment = decodeURIComponent(fragment.replace(routeStripper, ''));
       if (!fragment.indexOf(this.options.root)) fragment = fragment.substr(this.options.root.length);
       return fragment;
     },
@@ -778,7 +778,7 @@
         // Return immediately as browser will do redirect to new url
         return true;
       } else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
-        this.fragment = loc.hash.replace(hashStrip, '');
+        this.fragment = loc.hash.replace(routeStripper, '');
         window.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
       }
 
@@ -826,7 +826,7 @@
     // you which to modify the current URL without adding an entry to the history.
     navigate : function(fragment, options) {
       if (!options || options === true) options = {trigger: options};
-      var frag = (fragment || '').replace(hashStrip, '');
+      var frag = (fragment || '').replace(routeStripper, '');
       if (this.fragment == frag || this.fragment == decodeURIComponent(frag)) return;
       if (this._hasPushState) {
         if (frag.indexOf(this.options.root) != 0) frag = this.options.root + frag;
diff --git a/test/router.js b/test/router.js
index 4037322..02ebf40 100644
--- a/test/router.js
+++ b/test/router.js
@@ -97,8 +97,8 @@ $(document).ready(function() {
     equals(router.count, 0);
     router.navigate('counter', {trigger: true});
     equals(router.count, 1);
-    router.navigate('counter', {trigger: true});
-    router.navigate('counter', {trigger: true});
+    router.navigate('/counter', {trigger: true});
+    router.navigate('/counter', {trigger: true});
     equals(router.count, 1);
     router.navigate('search/counter', {trigger: true});
     router.navigate('counter', {trigger: true});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list