fix: 🐛 silently drop trailing slashes from origin input

This commit is contained in:
Randall Morey committed 2021-04-08 13:45:19 -04:00
1 parent 80cffeb48b
commit 0d8508cd4e
4 files changed
+21 -23

No files matched your search

+4
View File
@@ -63,6 +63,10 @@ export default class OriginService extends Service {
typeof origin === 'string'
);
try {
// Silently drop trailing slashes if present.
// This is important since API paths that will be appended to the origin
// will include preceeding slashes already.
origin = origin.replace(/\/*$/, '');
this.adapter.host = origin;
this.rendererOrigin = origin;
if (origin !== (await this.mainOrigin)) {
+1 -1
View File
@@ -3562,7 +3562,7 @@ xmlbuilder@^9.0.7:
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d"
integrity sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=
xmldom@0.1.x, xmldom@0.5.0:
xmldom@0.1.x, xmldom@~0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.5.0.tgz#193cb96b84aa3486127ea6272c4596354cb4962e"
integrity sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==
@@ -24,4 +24,15 @@ module('Unit | Service | origin', function (hooks) {
assert.equal(service.adapter.host, window.location.origin);
});
});
test('drops trailing slashes from origin on setOrigin', async function (assert) {
assert.expect(4);
sinon.stub(ipcService, 'invoke');
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}//////`);
assert.equal(service.rendererOrigin, window.location.origin);
assert.equal(service.adapter.host, window.location.origin);
});
});