Skip to content

Commit 50a8e88

Browse files
committed
Use double quotes to fix possible issue
1 parent a2be6e0 commit 50a8e88

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ public bool StartProcess(string filePath, string workingDirectory = "", string a
590590
var result = Win32Helper.RunAsDesktopUser(
591591
Constant.CommandExecutablePath,
592592
Environment.CurrentDirectory,
593-
$"-StartProcess -FileName {filePath} -WorkingDirectory {workingDirectory} -Arguments {arguments} -UseShellExecute {useShellExecute} -Verb {verb}",
593+
$"-StartProcess -FileName {AddDoubleQuotes(filePath)} -WorkingDirectory {AddDoubleQuotes(workingDirectory)} -Arguments {AddDoubleQuotes(arguments)} -UseShellExecute {useShellExecute} -Verb {AddDoubleQuotes(verb)}",
594594
out var errorInfo);
595595
if (!string.IsNullOrEmpty(errorInfo))
596596
{
@@ -619,7 +619,34 @@ public bool StartProcess(string filePath, string workingDirectory = "", string a
619619
}
620620

621621
public bool StartProcess(string filePath, string workingDirectory = "", Collection<string> argumentList = null, bool useShellExecute = true, string verb = "") =>
622-
StartProcess(filePath, workingDirectory, argumentList == null ? string.Empty : string.Join(" ", argumentList), useShellExecute, verb);
622+
StartProcess(filePath, workingDirectory, JoinArgumentList(argumentList), useShellExecute, verb);
623+
624+
private static string AddDoubleQuotes(string arg)
625+
{
626+
if (string.IsNullOrEmpty(arg))
627+
return "\"\"";
628+
629+
// If already wrapped in double quotes, return as is
630+
if (arg.Length >= 2 && arg[0] == '"' && arg[^1] == '"')
631+
return arg;
632+
633+
return $"\"{arg}\"";
634+
}
635+
636+
private static string JoinArgumentList(Collection<string> args)
637+
{
638+
if (args == null || args.Count == 0)
639+
return string.Empty;
640+
641+
return string.Join(" ", args.Select(arg =>
642+
{
643+
if (string.IsNullOrEmpty(arg))
644+
return "\"\"";
645+
646+
// Add double quotes
647+
return AddDoubleQuotes(arg);
648+
}));
649+
}
623650

624651
#endregion
625652

0 commit comments

Comments
 (0)