From a710d6d7cc92115181bdfc990a4a7d67c4d26930 Mon Sep 17 00:00:00 2001 From: bbedward Date: Thu, 30 Jul 2026 14:33:58 -0400 Subject: [PATCH] launcher: fix regex escaping launch args fixes #2961 port 1.5 --- quickshell/Services/SessionService.qml | 61 +++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/quickshell/Services/SessionService.qml b/quickshell/Services/SessionService.qml index 87f9b71bc..4a37dc646 100644 --- a/quickshell/Services/SessionService.qml +++ b/quickshell/Services/SessionService.qml @@ -219,6 +219,64 @@ Singleton { return envObj; } + function splitShellArgs(str) { + const args = []; + let current = ""; + let hasToken = false; + let quote = ""; + let escaped = false; + for (const ch of str) { + if (escaped) { + current += ch; + escaped = false; + continue; + } + switch (quote) { + case "'": + if (ch === "'") { + quote = ""; + continue; + } + current += ch; + continue; + case "\"": + switch (ch) { + case "\"": + quote = ""; + continue; + case "\\": + escaped = true; + continue; + } + current += ch; + continue; + } + switch (ch) { + case "\\": + escaped = true; + continue; + case "'": + case "\"": + quote = ch; + hasToken = true; + continue; + case " ": + case "\t": + case "\n": + if (!hasToken && current.length === 0) + continue; + args.push(current); + current = ""; + hasToken = false; + continue; + } + current += ch; + } + if (current.length > 0 || hasToken) + args.push(current); + return args; + } + function launchDesktopEntry(desktopEntry, useNvidia) { if (!desktopEntry || !desktopEntry.command) return; @@ -232,8 +290,7 @@ Singleton { cmd = [nvidiaCommand].concat(cmd); if (override?.extraFlags) { - const extraArgs = override.extraFlags.trim().split(/\s+/).filter(arg => arg.length > 0); - cmd = cmd.concat(extraArgs); + cmd = cmd.concat(splitShellArgs(override.extraFlags)); } const userPrefix = SettingsData.launchPrefix?.trim() || "";