Skip to content

Commit

Permalink
[BUGIX release] [Fixes #14925] remove duplicate / in pathname
Browse files Browse the repository at this point in the history
This avoids a DOMException, which interprets duplicate `/` as a security violation and prevents the associated history state modifications.
  • Loading branch information
stefanpenner committed Feb 25, 2017
1 parent a821583 commit 86c9c05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/ember-routing/lib/location/history_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions packages/ember-routing/tests/location/history_location_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '/');
});

0 comments on commit 86c9c05

Please sign in to comment.