diff --git a/backbone.js b/backbone.js index 08b463bcb..53ee3486d 100644 --- a/backbone.js +++ b/backbone.js @@ -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... @@ -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(); diff --git a/test/router.js b/test/router.js index f7522210e..5db996982 100644 --- a/test/router.js +++ b/test/router.js @@ -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 + }); + }); + });