diff --git a/app/locations/trailing-history.js b/app/locations/trailing-history.js index 0cb8dfb..675484e 100644 --- a/app/locations/trailing-history.js +++ b/app/locations/trailing-history.js @@ -10,6 +10,8 @@ export default HistoryLocation.extend({ export function formatURL(url) { let modifiedURL = new URL(url, 'http://example.com'); - modifiedURL.pathname += '/'; + if (!modifiedURL.pathname.endsWith('/')) { + modifiedURL.pathname += '/'; + } return `${modifiedURL.pathname}${modifiedURL.search}${modifiedURL.hash}`; } diff --git a/tests/unit/locations/trailing-history-test.js b/tests/unit/locations/trailing-history-test.js index c4bb8bf..1e6a01f 100644 --- a/tests/unit/locations/trailing-history-test.js +++ b/tests/unit/locations/trailing-history-test.js @@ -13,6 +13,10 @@ module('Unit | Locations | trailing history', function (hooks) { assert.deepEqual(formatURL('/foo#placeholder'), '/foo/#placeholder'); }); + test('does not add double slashes', function (assert) { + assert.deepEqual(formatURL('/foo/'), '/foo/'); + }); + test('supports query params and anchors', function (assert) { assert.deepEqual( formatURL('/foo?bar=baz#placeholder'),