From 7f15fb0a14a71cfba340647f5b23828eef054790 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 11 Mar 2019 13:58:27 -0500 Subject: [PATCH] (GH-1614) Fix: quote if pipe found in string In areas where we return pipe-delimited strings, it would be beneficial to quote text where a pipe could be used in the string itself. --- src/chocolatey/StringExtensions.cs | 15 +++++++++++++++ .../services/ChocolateyConfigSettingsService.cs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/StringExtensions.cs b/src/chocolatey/StringExtensions.cs index c9a638a939..8bc60fe3c6 100644 --- a/src/chocolatey/StringExtensions.cs +++ b/src/chocolatey/StringExtensions.cs @@ -195,5 +195,20 @@ public static string escape_curly_braces(this string input) return open_brace_regex.Replace(close_brace_regex.Replace(input,"}}"),"{{"); } + + /// + /// Surrounds with quotes if a pipe is found in the input string. + /// + /// The input. + /// The input, but with double quotes if there is a pipe character found in the string. + public static string quote_if_pipe_found(this string input) + { + if (string.IsNullOrWhiteSpace(input)) return input.to_string(); + + if (input.contains("|")) return "\"{0}\"".format_with(input); + + return input; + } + } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs index da81ed6a48..14fb95ee4b 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -78,7 +78,7 @@ public virtual IEnumerable source_list(ChocolateyConfiguration source.Id, source.Value, source.Disabled.to_string(), - source.UserName, + source.UserName.quote_if_pipe_found(), source.Certificate, source.Priority, source.BypassProxy.to_string(),