fix: Trim first to avoid leaving trailing slashes in origin
This commit is contained in:
2 files changed
+4
-4
No files matched your search
@@ -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} `);
|
||||
|
||||
Reference in new issue
Block a user