From 97030f7ef301a0600e53e98f883de0f79efd15f0 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 1 Apr 2021 17:44:55 +0200 Subject: [PATCH] add https to homeserver if not already a valid url --- src/matrix/SessionContainer.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index 85a6826d..57752309 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -43,6 +43,14 @@ export const LoginFailure = createEnum( "Unknown", ); +function normalizeHomeserver(homeServer) { + try { + return new URL(homeServer).origin; + } catch (err) { + return new URL(`https://${homeServer}`).origin; + } +} + export class SessionContainer { constructor({platform, olmPromise, workerPromise}) { this._platform = platform; @@ -96,6 +104,7 @@ export class SessionContainer { } await this._platform.logger.run("login", async log => { this._status.set(LoadStatus.Login); + homeServer = normalizeHomeserver(homeServer); const clock = this._platform.clock; let sessionInfo; try {