Skip to content

Commit

Permalink
Avoid calling pushState with an empty url.
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Jul 5, 2013
1 parent 151bd73 commit 15b7d77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@
var url = this.root + fragment;

// Don't include a trailing slash on the root.
if (fragment === '') url = url.slice(0, -1);
if (fragment === '' && url !== '/') url = url.slice(0, -1);

// If pushState is available, we use it to set the fragment as a real URL.
if (this._hasPushState) {
Expand Down
15 changes: 15 additions & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,19 @@ $(document).ready(function() {
Backbone.history.navigate('');
});

test('#2656 - No 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, '/');
}
}
});
location.replace('http://example.com/path');
Backbone.history.start({pushState: true});
Backbone.history.navigate('');
});

});

0 comments on commit 15b7d77

Please sign in to comment.