Skip to content

Commit

Permalink
fix(history): fix url turning into /undefined in IE11/Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Oct 25, 2015
1 parent 55bc47d commit 257a4a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ export class HistoryBindingNatural_ {
};
replaceState = (state, opt_title, opt_url) => {
this.unsupportedState_ = state;
this.origReplaceState_(state, opt_title, opt_url);
// NOTE: check for `undefined` since IE11 and Edge
// unexpectedly coerces it into a `string`.
if (opt_url !== undefined) {
this.origReplaceState_(state, opt_title, opt_url);
} else {
this.origReplaceState_(state, opt_title);
}
};
} else {
pushState = (state, opt_title, opt_url) => {
Expand Down
16 changes: 16 additions & 0 deletions test/functional/test-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ describe('HistoryBindingNatural', () => {
expect(onStackIndexUpdated.callCount).to.equal(0);
});

// This prevents IE11/Edge from coercing undefined to become the new url
it('should not pass in `url` argument to original replace state if ' +
'parameter is undefined', () => {
let argumentLength = 0;
let origReplace = window.history.replaceState;
window.history.replaceState = function() {
argumentLength = arguments.length;
};

let history2 = new HistoryBindingNatural_(window);

expect(argumentLength).to.equal(2);

window.history.replaceState = origReplace;
});

it('should push new state in the window.history and notify', () => {
return history.push().then((stackIndex) => {
expect(history.stackIndex_).to.equal(stackIndex);
Expand Down

0 comments on commit 257a4a5

Please sign in to comment.