Skip to content

Commit

Permalink
(GH-1614) Fix: quote if pipe found in string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Mar 11, 2019
1 parent 8822afb commit 7f15fb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/chocolatey/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,20 @@ public static string escape_curly_braces(this string input)

return open_brace_regex.Replace(close_brace_regex.Replace(input,"}}"),"{{");
}

/// <summary>
/// Surrounds with quotes if a pipe is found in the input string.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>The input, but with double quotes if there is a pipe character found in the string.</returns>
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;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public virtual IEnumerable<ChocolateySource> 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(),
Expand Down

0 comments on commit 7f15fb0

Please sign in to comment.