Skip to content

Commit

Permalink
Fix duplicate query string params when hashbang is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoan-JNPR committed Jan 24, 2021
1 parent 4f99916 commit 5ce2222
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
var loc = window.location;

if(this._hashbang && ~loc.hash.indexOf('#!')) {
url = loc.hash.substr(2) + loc.search;
url = loc.hash.substr(2) + (~loc.hash.indexOf('?') ? '' : loc.search);
} else if (this._hashbang) {
url = loc.search + loc.hash;
} else {
Expand Down
2 changes: 1 addition & 1 deletion page.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
var loc = window.location;

if(this._hashbang && ~loc.hash.indexOf('#!')) {
url = loc.hash.substr(2) + loc.search;
url = loc.hash.substr(2) + (~loc.hash.indexOf('?') ? '' : loc.search);
} else if (this._hashbang) {
url = loc.search + loc.hash;
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/support/jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function setupJsdom(options, next) {
function setupGlobals(window) {
window.console = console;
if(window.location.protocol !== 'file:')
window.history.replaceState(null, '', '/');
window.history.replaceState(null, '', '/' + options.qs || '');
global.window = window;
global.location = window.location;
global.document = window.document;
Expand Down
24 changes: 24 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,30 @@
});
});

describei('When hashbang option enabled with base query params', function() {
before(function(done){
jsdomSupport.setup({
qs: '?hello=there'
}, done);
});

it('prevents duplicate query params added to hash', function(done) {
var count = 0;

baseRoute = function () {
expect(window.location.search).to.equal('?hello=there');
expect(window.location.hash).to.equal('#!?hello=there');

count++;
count === 2 && done();
};

page({ hashbang: true });
page({ hashbang: true });
});
});


describe('Route', function() {
before(function(done) {
beforeTests(null, done);
Expand Down

0 comments on commit 5ce2222

Please sign in to comment.