Skip to content

Commit

Permalink
Merge pull request #14961 from emberjs/duplicate-slashes
Browse files Browse the repository at this point in the history
[BUGIX release] [Fixes #14925] remove duplicate `/` in pathname
  • Loading branch information
stefanpenner authored Apr 5, 2017
2 parents e255d73 + fe88d54 commit 08a6719
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 08a6719

Please sign in to comment.