diff --git a/packages/ember-routing/lib/location/history_location.js b/packages/ember-routing/lib/location/history_location.js index 9e632fc6134..f296d452d4e 100644 --- a/packages/ember-routing/lib/location/history_location.js +++ b/packages/ember-routing/lib/location/history_location.js @@ -101,7 +101,8 @@ export default EmberObject.extend({ // remove baseURL and rootURL from start of path let url = path .replace(new RegExp(`^${baseURL}(?=/|$)`), '') - .replace(new RegExp(`^${rootURL}(?=/|$)`), ''); + .replace(new RegExp(`^${rootURL}(?=/|$)`), '') + .replace(/\/\//g,'/'); // remove extra slashes let search = location.search || ''; url += search + this.getHash(); diff --git a/packages/ember-routing/tests/location/history_location_test.js b/packages/ember-routing/tests/location/history_location_test.js index 034ba8efd23..7cc803bf548 100644 --- a/packages/ember-routing/tests/location/history_location_test.js +++ b/packages/ember-routing/tests/location/history_location_test.js @@ -333,3 +333,21 @@ QUnit.test('HistoryLocation.getURL() includes location.hash and location.search' equal(location.getURL(), '/foo/bar?time=morphin#pink-power-ranger'); }); + + +QUnit.test('HistoryLocation.getURL() drops duplicate slashes', function() { + expect(1); + + HistoryTestLocation.reopen({ + init() { + this._super(...arguments); + let location = mockBrowserLocation('//'); + location.pathname = '//'; // mockBrowserLocation does not allow for `//`, so force it + set(this, 'location', location); + } + }); + + createLocation(); + + equal(location.getURL(), '/'); +});