fix: Trim first to avoid leaving trailing slashes in origin

This commit is contained in:
Susmitha Girumala committed 2021-04-13 16:57:07 -04:00
1 parent e894dbc4e8
commit 1a901b15d2
2 files changed
+4 -4

No files matched your search

+3 -3
View File
@@ -63,11 +63,11 @@ export default class OriginService extends Service {
typeof origin === 'string'
);
try {
// Silently drop trailing slashes if present.
// Trim whitespaces and silently drop trailing slashes if present.
// This is important since API paths that will be appended to the origin
// will include preceeding slashes already.
// Trim whitespaces around origin.
origin = origin.replace(/\/*$/, '').trim();
origin = origin.trim();
origin = origin.replace(/\/*$/, '');
this.adapter.host = origin;
this.rendererOrigin = origin;
if (origin !== (await this.mainOrigin)) {
@@ -39,7 +39,7 @@ module('Unit | Service | origin', function (hooks) {
test('trim spaces from origin on setOrigin', async function (assert) {
assert.expect(4);
sinon.stub(ipcService, 'invoke');
await service.setOrigin(` ${window.location.origin} `);
await service.setOrigin(` ${window.location.origin}/ `);
assert.equal(service.rendererOrigin, window.location.origin);
assert.equal(service.adapter.host, window.location.origin);
await service.setOrigin(` ${window.location.origin} `);