1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-01 19:18:28 -04:00

launcher: fix regex escaping launch args

fixes #2961
port 1.5
This commit is contained in:
bbedward
2026-07-30 14:33:58 -04:00
parent 64461c534f
commit a710d6d7cc
+59 -2
View File
@@ -219,6 +219,64 @@ Singleton {
return envObj; 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) { function launchDesktopEntry(desktopEntry, useNvidia) {
if (!desktopEntry || !desktopEntry.command) if (!desktopEntry || !desktopEntry.command)
return; return;
@@ -232,8 +290,7 @@ Singleton {
cmd = [nvidiaCommand].concat(cmd); cmd = [nvidiaCommand].concat(cmd);
if (override?.extraFlags) { if (override?.extraFlags) {
const extraArgs = override.extraFlags.trim().split(/\s+/).filter(arg => arg.length > 0); cmd = cmd.concat(splitShellArgs(override.extraFlags));
cmd = cmd.concat(extraArgs);
} }
const userPrefix = SettingsData.launchPrefix?.trim() || ""; const userPrefix = SettingsData.launchPrefix?.trim() || "";