From 257a4a516c551422ac4d2ae7cd879ac405a1a420 Mon Sep 17 00:00:00 2001 From: Erwin Mombay Date: Sun, 25 Oct 2015 03:27:02 -0700 Subject: [PATCH] fix(history): fix url turning into /undefined in IE11/Edge --- src/history.js | 8 +++++++- test/functional/test-history.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/history.js b/src/history.js index 97c5dedaee8d..3683ab149dbd 100644 --- a/src/history.js +++ b/src/history.js @@ -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) => { diff --git a/test/functional/test-history.js b/test/functional/test-history.js index f8fb97bcaf25..7e2cdfd99406 100644 --- a/test/functional/test-history.js +++ b/test/functional/test-history.js @@ -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);