From 151bd73d26ab92de3c224ded656e535a06d7e85b Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Fri, 5 Jul 2013 16:00:45 -0400 Subject: [PATCH] Never include trailing slash on the root. --- backbone.js | 6 +++--- test/router.js | 17 +---------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/backbone.js b/backbone.js index 69514cf71..aaf6eb00a 100644 --- a/backbone.js +++ b/backbone.js @@ -1473,14 +1473,14 @@ if (!History.started) return false; if (!options || options === true) options = {trigger: !!options}; - var trailing = fragment === '/'; fragment = this.getFragment(fragment || ''); - if (this.fragment === fragment) return; this.fragment = fragment; var url = this.root + fragment; - if (!trailing && fragment === '') url = url.slice(0, -1); + + // Don't include a trailing slash on the root. + if (fragment === '') url = url.slice(0, -1); // If pushState is available, we use it to set the fragment as a real URL. if (this._hasPushState) { diff --git a/test/router.js b/test/router.js index a5cdcf481..6206263a3 100644 --- a/test/router.js +++ b/test/router.js @@ -656,7 +656,7 @@ $(document).ready(function() { Backbone.history.checkUrl(); }); - test('Trailing slash on root.', 1, function() { + test('#2656 - No trailing slash on root.', 1, function() { Backbone.history.stop(); Backbone.history = _.extend(new Backbone.History, { location: location, @@ -671,19 +671,4 @@ $(document).ready(function() { Backbone.history.navigate(''); }); - test('Trailing slash on root.', 1, function() { - Backbone.history.stop(); - Backbone.history = _.extend(new Backbone.History, { - location: location, - history: { - pushState: function(state, title, url){ - strictEqual(url, '/root/'); - } - } - }); - location.replace('http://example.com/root/path'); - Backbone.history.start({pushState: true, root: 'root'}); - Backbone.history.navigate('/'); - }); - });