Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1695 - Ignore location.search during pushState transition. #1696

Merged
merged 1 commit into from
Oct 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix #1695 - Ignore location.search during pushState transition.
  • Loading branch information
braddunbar committed Oct 2, 2012
commit 3f530c2ab5002f9ac79b6658575c781e0b034250
4 changes: 2 additions & 2 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@
// opened by a non-pushState browser.
this.fragment = fragment;
var loc = this.location;
var atRoot = (loc.pathname.replace(/[^\/]$/, '$&/') === this.root) && !loc.search;
var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root;

// If we've started off with a route from a `pushState`-enabled browser,
// but we're currently in a browser that doesn't support it...
Expand All @@ -1073,7 +1073,7 @@
// in a browser where it could be `pushState`-based instead...
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
this.fragment = this.getHash().replace(routeStripper, '');
this.history.replaceState({}, document.title, this.root + this.fragment);
this.history.replaceState({}, document.title, this.root + this.fragment + loc.search);
}

if (!this.options.silent) return this.loadUrl();
Expand Down
18 changes: 18 additions & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,22 @@ $(document).ready(function() {
});
});

test("#1695 - hashChange to pushState with search.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root?a=b#x/y');
Backbone.history = _.extend(new Backbone.History, {
location: location,
history: {
pushState: function(){},
replaceState: function(state, title, url){
strictEqual(url, '/root/x/y?a=b');
}
}
});
Backbone.history.start({
root: 'root',
pushState: true
});
});

});