From 0de93ac814ac782905ce5e665a9d8a69d6b81848 Mon Sep 17 00:00:00 2001 From: Denis Gladkiy Date: Tue, 14 Oct 2025 09:35:18 +0600 Subject: [PATCH 1/2] CLI argument sanitizing: removing trailing slashes in the server URL. Signed-off-by: Denis Gladkiy --- desktop/src/__test__/main/settings.test.ts | 11 +++++++---- desktop/src/main/settings.ts | 6 +++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/desktop/src/__test__/main/settings.test.ts b/desktop/src/__test__/main/settings.test.ts index 3db1f225b98..0c6a3564570 100644 --- a/desktop/src/__test__/main/settings.test.ts +++ b/desktop/src/__test__/main/settings.test.ts @@ -159,10 +159,13 @@ describe('Settings', () => { }) describe('setServerUrl', () => { - test('write than read', () => { - const expectedUrl = 'https://new.server.com' - - systemUnderTest.setServerUrl(expectedUrl) + const expectedUrl = 'https://new.server.com' + test.each([ + { serverUrl: 'https://new.server.com' }, + { serverUrl: 'https://new.server.com/' }, + { serverUrl: 'https://new.server.com//' } + ])('write $serverUrl than read', ({ serverUrl }) => { + systemUnderTest.setServerUrl(serverUrl) expect(systemUnderTest.readServerUrl()).toBe(expectedUrl) }) diff --git a/desktop/src/main/settings.ts b/desktop/src/main/settings.ts index 1996b231412..30886133ceb 100644 --- a/desktop/src/main/settings.ts +++ b/desktop/src/main/settings.ts @@ -52,7 +52,11 @@ export class Settings { } setServerUrl (serverUrl: string): void { - (this.store as any).set(Settings.SETTINGS_KEY_SERVER, serverUrl) + let cleanUrl: string = serverUrl + while (cleanUrl.endsWith('/')) { + cleanUrl = cleanUrl.slice(0, -1) + } + (this.store as any).set(Settings.SETTINGS_KEY_SERVER, cleanUrl) } getWindowBounds (): any { From 7ebfe50f1dcd3e3e3d4a2a0cea6d327381cec6ca Mon Sep 17 00:00:00 2001 From: Denis Gladkiy Date: Tue, 14 Oct 2025 10:06:32 +0600 Subject: [PATCH 2/2] Sanitizing saved on disk urls. Signed-off-by: Denis Gladkiy --- desktop/src/main/settings.ts | 39 +++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/desktop/src/main/settings.ts b/desktop/src/main/settings.ts index 30886133ceb..53f9e244aba 100644 --- a/desktop/src/main/settings.ts +++ b/desktop/src/main/settings.ts @@ -32,15 +32,9 @@ export class Settings { } readServerUrl (): string { - if (this.isDev) { - return process.env.FRONT_URL ?? 'http://huly.local:8087' - } - return ( - (this.store as any).get(Settings.SETTINGS_KEY_SERVER) as string ?? - this.packedConfig?.server ?? - process.env.FRONT_URL ?? - 'https://huly.app' - ) + const url = this.extractUrl() + // Motivation: fix existing Huly installations (saved on disk URLs). + return Settings.sanitizeUrl(url) } isMinimizeToTrayEnabled (): boolean { @@ -52,11 +46,8 @@ export class Settings { } setServerUrl (serverUrl: string): void { - let cleanUrl: string = serverUrl - while (cleanUrl.endsWith('/')) { - cleanUrl = cleanUrl.slice(0, -1) - } - (this.store as any).set(Settings.SETTINGS_KEY_SERVER, cleanUrl) + const sanitizedUrl: string = Settings.sanitizeUrl(serverUrl) + ;(this.store as any).set(Settings.SETTINGS_KEY_SERVER, sanitizedUrl) } getWindowBounds (): any { @@ -66,4 +57,24 @@ export class Settings { setWindowBounds (bounds: any): void { (this.store as any).set(Settings.SETTINGS_KEY_WINDOW_BOUNDS, bounds) } + + private extractUrl (): string { + if (this.isDev) { + return process.env.FRONT_URL ?? 'http://huly.local:8087' + } + return ( + (this.store as any).get(Settings.SETTINGS_KEY_SERVER) as string ?? + this.packedConfig?.server ?? + process.env.FRONT_URL ?? + 'https://huly.app' + ) + } + + private static sanitizeUrl (serverUrl: string): string { + let cleanUrl: string = serverUrl + while (cleanUrl.endsWith('/')) { + cleanUrl = cleanUrl.slice(0, -1) + } + return cleanUrl + } }