From 088cfd232a518d5612b2df713ea953d6e098d553 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 27 Oct 2011 09:18:02 -0700 Subject: [PATCH] WinSW should handle whitespace in the argument correctly Cherry picked 83380bdd9b801d82022ca58d9637300494f1ee8b --- ServiceDescriptor.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ServiceDescriptor.cs b/ServiceDescriptor.cs index ee9536b..a8a5edd 100755 --- a/ServiceDescriptor.cs +++ b/ServiceDescriptor.cs @@ -157,7 +157,7 @@ namespace winsw /// /// Combines the contents of all the elements of the given name, - /// or return null if no element exists. + /// or return null if no element exists. Handles whitespace quotatoin. /// private string AppendTags(string tagName) { @@ -173,7 +173,22 @@ namespace winsw foreach (XmlNode argument in dom.SelectNodes("//" + tagName)) { - arguments += " " + argument.InnerText; + string token = argument.InnerText; + + if (token.StartsWith("\"") && token.EndsWith("\"")) + { + // for backward compatibility, if the argument is already quoted, leave it as is. + // in earlier versions we didn't handle quotation, so the user might have worked + // around it by themselves + } + else + { + if (token.Contains(" ")) + { + token = '"' + token + '"'; + } + } + arguments += " " + token; } return Environment.ExpandEnvironmentVariables(arguments);