TypeScript
fix(desktop): Linux URL handler quotes the Exec path only when it must (#16670)
Igor Makowski29d46101f3e5
diff --git a/apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts b/apps/desktop/src/app/DesktopLinuxUrlHandler.test.tsindex e6900a03b7d..295f63eafe4 100644--- a/apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts+++ b/apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts@@ -179,6 +179,25 @@ describe("DesktopLinuxUrlHandler", () => {assert.include(entry, "Icon=/home/al ice/icons/T3\\\\x.png");});+ it.each([+ {+ execTarget: "/opt/T3(beta)/t3code.AppImage",+ execLine: 'Exec="/opt/T3(beta)/t3code.AppImage" %U',+ },+ {+ execTarget: "/opt/t3%20code/t3code.AppImage",+ execLine: "Exec=/opt/t3%%20code/t3code.AppImage %U",+ },+ ])("renders the handler Exec line for $execTarget", ({ execTarget, execLine }) => {+ const entry = DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({+ displayName: "T3 Code",+ execTarget,+ scheme: "t3code",+ });++ assert.include(entry.split("\n"), execLine);+ });+it("carries structured context on registration errors", () => {const writeError = new DesktopLinuxUrlHandler.DesktopLinuxUrlHandlerRegistrationError({step: "write-desktop-entry",@@ -222,7 +241,7 @@ describe("DesktopLinuxUrlHandler", () => {);assert.include(recorded.files[0]?.content,- 'Exec="/home/alice/Applications/T3-Code.AppImage" %U',+ "Exec=/home/alice/Applications/T3-Code.AppImage %U",);assert.include(recorded.files[0]?.content, "MimeType=x-scheme-handler/t3code;");assert.deepEqual(recorded.commands, [@@ -247,7 +266,12 @@ describe("DesktopLinuxUrlHandler", () => {assert.include(recorded.files[0]?.content,- `Exec=${DesktopLinuxUrlHandler.escapeDesktopEntryExecArgument(process.execPath)} %U`,+ DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({+ displayName: "T3 Code (Alpha)",+ execTarget: process.execPath,+ scheme: "t3code",+ iconPath: "/home/alice/.local/share/icons/com.t3tools.T3Code.desktop.png",+ }),);});});diff --git a/apps/desktop/src/app/DesktopLinuxUrlHandler.ts b/apps/desktop/src/app/DesktopLinuxUrlHandler.tsindex 08cd1d47c08..e03418964e3 100644--- a/apps/desktop/src/app/DesktopLinuxUrlHandler.ts+++ b/apps/desktop/src/app/DesktopLinuxUrlHandler.ts@@ -75,6 +75,12 @@ export function escapeDesktopEntryExecArgument(value: string): string {return escapeDesktopEntryString(`"${quoted}"`);}+// Legacy xdg-open looks up the first Exec word without unquoting it.+const escapeUrlHandlerExecTarget = (value: string): string =>+ /[ \t\n"'\\><~|&;$*?#()`]/.test(value)+ ? escapeDesktopEntryExecArgument(value)+ : escapeDesktopEntryString(value.replaceAll("%", "%%"));+// The AppImage integration entry owns the window identity. This// hidden URL-only entry must not compete with it for StartupWMClass matching.export function renderUrlHandlerDesktopEntry(input: {@@ -87,7 +93,7 @@ export function renderUrlHandlerDesktopEntry(input: {"[Desktop Entry]","Type=Application",`Name=${escapeDesktopEntryString(input.displayName)}`,- `Exec=${escapeDesktopEntryExecArgument(input.execTarget)} %U`,+ `Exec=${escapeUrlHandlerExecTarget(input.execTarget)} %U`,...(input.iconPath === undefined ? [] : [`Icon=${escapeDesktopEntryString(input.iconPath)}`]),"Terminal=false","NoDisplay=true",diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.test.tsindex dd15f879fd8..845e89331f9 100644--- a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts+++ b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts@@ -174,7 +174,7 @@ describe("DesktopPreReadyPlatform", () => {);const identity = yield* Effect.promise(() => portalIdentity);assert.equal(identity.desktopName, "com.t3tools.T3Code.desktop");- assert.include(identity.desktopEntry ?? "", 'Exec="/Applications/current.AppImage" %U');+ assert.include(identity.desktopEntry ?? "", "Exec=/Applications/current.AppImage %U");assert.include(identity.desktopEntry ?? "", "Name=T3 Code (Beta)");assert.include(identity.desktopEntry ?? "", "MimeType=x-scheme-handler/t3code;");assert.include(