Skip to content

Commit

Permalink
Merge pull request #746 from erwinmombay/edge
Browse files Browse the repository at this point in the history
fix(history): fix url turning into /undefined in IE11/Edge
  • Loading branch information
erwinmombay committed Oct 25, 2015
2 parents 55bc47d + 257a4a5 commit f268934
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 f268934

Please sign in to comment.