aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Integrations/Scripts/ScriptService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Integrations/Scripts/ScriptService.cs')
-rw-r--r--src/slskd/Integrations/Scripts/ScriptService.cs26
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);