Skip to content

Commit

Permalink
Issue jashkenas#1793: Backbone.history.navigate should use this.getFr…
Browse files Browse the repository at this point in the history
…agment instead of fragment to avoid routes getting triggered twice
  • Loading branch information
djbriane committed Nov 2, 2012
1 parent aeaf2ee commit 8decce8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@
} else {
return this.location.assign(url);
}
if (options.trigger) this.loadUrl(fragment);
if (options.trigger) this.loadUrl(this.getFragment() || fragment);
},

// Update the hash location, either replacing the current entry, or adding
Expand Down
55 changes: 55 additions & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,59 @@ $(document).ready(function() {
new Router;
});

test("#1793 Trailing spaces (pushState:false).", 1, function() {
var count = 0;

Backbone.history.stop();

// restart History with pushState:false
Backbone.history.start({
pushState: false
});

router.on("route:search", function(page) {
count = count + 1;
});

// navigate to the search route with trailing space in the query string
Backbone.history.navigate('search/space ', {trigger: true});

// manually fire checkUrl
Backbone.history.checkUrl();

equal(count, 1); // route event should be fired once

router.off("route:search"); //unbind events
});

test("#1793 Trailing spaces using browser location (pushState: false).", 1, function() {
var count = 0;

Backbone.history.stop();
Backbone.history.location = window.location; // Use browser location

// restart History with pushState:false
Backbone.history.start({
pushState: false
});

router.on("route:search", function(page) {
count = count + 1;
});

// navigate to the search route with trailing space in the query string
Backbone.history.navigate('search/space ', {trigger: true});

// manually fire checkUrl
Backbone.history.checkUrl();

equal(count, 1); // route event should be fired only once

router.off("route:search"); //unbind events

// restore location hash
window.location.hash = '';

});

});

0 comments on commit 8decce8

Please sign in to comment.