From 495cad717d15b67c889e7d5996222ff46959cf12 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:38:33 +0200 Subject: [PATCH] refactor(desktop): tighten autoLaunch helpers per code review --- packages/desktop/src/autoLaunch.test.ts | 9 +++++++++ packages/desktop/src/autoLaunch.ts | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/desktop/src/autoLaunch.test.ts b/packages/desktop/src/autoLaunch.test.ts index f3d0e9f3..f7f83021 100644 --- a/packages/desktop/src/autoLaunch.test.ts +++ b/packages/desktop/src/autoLaunch.test.ts @@ -47,6 +47,15 @@ describe('parseExecPathFromDesktopFile', () => { it('returns null on empty input', () => { expect(parseExecPathFromDesktopFile('')).toBeNull(); }); + + it('returns null on an empty quoted Exec= path', () => { + expect(parseExecPathFromDesktopFile('Exec=""\n')).toBeNull(); + }); + + it('handles CRLF line endings', () => { + const content = '[Desktop Entry]\r\nExec=/opt/Backspace/backspace --hidden\r\n'; + expect(parseExecPathFromDesktopFile(content)).toBe('/opt/Backspace/backspace'); + }); }); describe('shouldReapplyAppImage', () => { diff --git a/packages/desktop/src/autoLaunch.ts b/packages/desktop/src/autoLaunch.ts index 808cfcab..0aaeec6f 100644 --- a/packages/desktop/src/autoLaunch.ts +++ b/packages/desktop/src/autoLaunch.ts @@ -18,12 +18,13 @@ export function parseExecPathFromDesktopFile(content: string): string | null { const line = raw.trim(); if (!line || line.startsWith('#')) continue; if (!line.startsWith('Exec=')) continue; - const value = line.slice('Exec='.length).trimStart(); + const value = line.slice('Exec='.length); if (!value) continue; if (value.startsWith('"')) { const end = value.indexOf('"', 1); if (end === -1) return null; - return value.slice(1, end); + const extracted = value.slice(1, end); + return extracted === '' ? null : extracted; } const sp = value.indexOf(' '); return sp === -1 ? value : value.slice(0, sp);