From ddd0dbff4604d484fb058197539879208b281a3e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 9 Feb 2025 17:50:05 -0600 Subject: support quoted executable strings --- src/slskd/Integrations/Scripts/ScriptService.cs | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/slskd/Integrations/Scripts/ScriptService.cs') diff --git a/src/slskd/Integrations/Scripts/ScriptService.cs b/src/slskd/Integrations/Scripts/ScriptService.cs index a6ddb251..d4eb0bb1 100644 --- a/src/slskd/Integrations/Scripts/ScriptService.cs +++ b/src/slskd/Integrations/Scripts/ScriptService.cs @@ -69,16 +69,28 @@ public class ScriptService try { var run = script.Value.Run; - - // split the string into at most 2 parts, leaving part [0] the executable and part [1] the rest of the string, but possibly null - var parts = run.Split(" ", count: 2, options: StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.RemoveEmptyEntries); - - var executable = parts[0]; + string executable = default; string args = default; - if (parts.Length > 1) + // determine whether the executable is wrapped in quotes, and if so, set the executable to the + // text contained within. the regex contains two capturing groups; the initial quoted string, and + // everything that comes after. if both groups capture something, we were given a quoted string to start + // otherwise no quotes were used, and we should use the first word as the executable + var matches = LeadingQuotedString.Matches(run); + + if (matches.Count == 2) { - args = parts[1].Replace("$DATA", data.ToJson()); + executable = matches[0].Value; + args = matches[1].Value; + } + else + { + // didn't start with a quoted string, so just split the string into at most 2 parts, leaving + // part [0] the executable and part [1] the rest of the string (but possibly null) + var parts = run.Split(" ", count: 2, options: StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.RemoveEmptyEntries); + + executable = parts[0]; + args = parts.Length > 1 ? parts[1] : null; } Log.Debug("Running script '{Script}': {Run}", script.Key, run); -- cgit v1.2.3