Skip to content

Commit 29d4610

Browse files
fix(desktop): Linux URL handler quotes the Exec path only when it must (pingdotgg#16670)
Co-authored-by: Julius Marminge <[email protected]>
1 parent e1931b5 commit 29d4610

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,25 @@ describe("DesktopLinuxUrlHandler", () => {
179179
assert.include(entry, "Icon=/home/al ice/icons/T3\\\\x.png");
180180
});
181181

182+
it.each([
183+
{
184+
execTarget: "/opt/T3(beta)/t3code.AppImage",
185+
execLine: 'Exec="/opt/T3(beta)/t3code.AppImage" %U',
186+
},
187+
{
188+
execTarget: "/opt/t3%20code/t3code.AppImage",
189+
execLine: "Exec=/opt/t3%%20code/t3code.AppImage %U",
190+
},
191+
])("renders the handler Exec line for $execTarget", ({ execTarget, execLine }) => {
192+
const entry = DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
193+
displayName: "T3 Code",
194+
execTarget,
195+
scheme: "t3code",
196+
});
197+
198+
assert.include(entry.split("\n"), execLine);
199+
});
200+
182201
it("carries structured context on registration errors", () => {
183202
const writeError = new DesktopLinuxUrlHandler.DesktopLinuxUrlHandlerRegistrationError({
184203
step: "write-desktop-entry",
@@ -222,7 +241,7 @@ describe("DesktopLinuxUrlHandler", () => {
222241
);
223242
assert.include(
224243
recorded.files[0]?.content,
225-
'Exec="/home/alice/Applications/T3-Code.AppImage" %U',
244+
"Exec=/home/alice/Applications/T3-Code.AppImage %U",
226245
);
227246
assert.include(recorded.files[0]?.content, "MimeType=x-scheme-handler/t3code;");
228247
assert.deepEqual(recorded.commands, [
@@ -247,7 +266,12 @@ describe("DesktopLinuxUrlHandler", () => {
247266

248267
assert.include(
249268
recorded.files[0]?.content,
250-
`Exec=${DesktopLinuxUrlHandler.escapeDesktopEntryExecArgument(process.execPath)} %U`,
269+
DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
270+
displayName: "T3 Code (Alpha)",
271+
execTarget: process.execPath,
272+
scheme: "t3code",
273+
iconPath: "/home/alice/.local/share/icons/com.t3tools.T3Code.desktop.png",
274+
}),
251275
);
252276
});
253277
});

‎apps/desktop/src/app/DesktopLinuxUrlHandler.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export function escapeDesktopEntryExecArgument(value: string): string {
7575
return escapeDesktopEntryString(`"${quoted}"`);
7676
}
7777

78+
// Legacy xdg-open looks up the first Exec word without unquoting it.
79+
const escapeUrlHandlerExecTarget = (value: string): string =>
80+
/[ \t\n"'\\><~|&;$*?#()`]/.test(value)
81+
? escapeDesktopEntryExecArgument(value)
82+
: escapeDesktopEntryString(value.replaceAll("%", "%%"));
83+
7884
// The AppImage integration entry owns the window identity. This
7985
// hidden URL-only entry must not compete with it for StartupWMClass matching.
8086
export function renderUrlHandlerDesktopEntry(input: {
@@ -87,7 +93,7 @@ export function renderUrlHandlerDesktopEntry(input: {
8793
"[Desktop Entry]",
8894
"Type=Application",
8995
`Name=${escapeDesktopEntryString(input.displayName)}`,
90-
`Exec=${escapeDesktopEntryExecArgument(input.execTarget)} %U`,
96+
`Exec=${escapeUrlHandlerExecTarget(input.execTarget)} %U`,
9197
...(input.iconPath === undefined ? [] : [`Icon=${escapeDesktopEntryString(input.iconPath)}`]),
9298
"Terminal=false",
9399
"NoDisplay=true",

‎apps/desktop/src/app/DesktopPreReadyPlatform.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe("DesktopPreReadyPlatform", () => {
174174
);
175175
const identity = yield* Effect.promise(() => portalIdentity);
176176
assert.equal(identity.desktopName, "com.t3tools.T3Code.desktop");
177-
assert.include(identity.desktopEntry ?? "", 'Exec="/Applications/current.AppImage" %U');
177+
assert.include(identity.desktopEntry ?? "", "Exec=/Applications/current.AppImage %U");
178178
assert.include(identity.desktopEntry ?? "", "Name=T3 Code (Beta)");
179179
assert.include(identity.desktopEntry ?? "", "MimeType=x-scheme-handler/t3code;");
180180
assert.include(

0 commit comments

Comments
 (0)