diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-02-09 17:50:05 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-02-09 17:50:05 -0600 |
| commit | ddd0dbff4604d484fb058197539879208b281a3e (patch) | |
| tree | 0379ab06510a3f582ad49c8ddf421542b80847ab /src/slskd/Integrations/Scripts | |
| parent | ba85ca83c1ca1a394a938497019404a11ecbf5bb (diff) | |
| download | slskd-ddd0dbff4604d484fb058197539879208b281a3e.tar.gz | |
support quoted executable strings
Diffstat (limited to 'src/slskd/Integrations/Scripts')
| -rw-r--r-- | src/slskd/Integrations/Scripts/ScriptService.cs | 26 |
1 files changed, 19 insertions, 7 deletions
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); |
