Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Nov 10, 2023
1 parent 96cdf04 commit dec8329
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Tests/SonarScanner.MSBuild.Common.Test/ProcessRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void ProcRunner_ArgumentQuoting()
[DataRow(@"]", @"]")]
[DataRow(@"!", @"!")]
[DataRow(@".", @".")]
[DataRow(@"*", @"*")]
[DataRow(@"*", @"* ")] // See ProcRunner_ArgumentQuotingForwardedByBatchScriptToJava
[DataRow(@"?", @"?")]
[DataRow(@"=", @"""=""")]
[DataRow(@"a=b", @"""a=b""")]
Expand Down Expand Up @@ -398,7 +398,7 @@ public void ProcRunner_ArgumentQuotingForwardedByBatchScript(string parameter, s
[DataRow(@"]", @"]")]
[DataRow(@"!", @"!")]
[DataRow(@".", @".")]
[DataRow(@"*", @"*")]
[DataRow(@"*", @"* ")] // See ProcRunner_ArgumentQuotingForwardedByBatchScriptToJava
[DataRow(@"?", @"?")]
[DataRow(@"=", @"=")]
[DataRow(@"a=b", @"a=b")]
Expand Down
8 changes: 4 additions & 4 deletions src/SonarScanner.MSBuild.Common/ProcessRunnerArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ static string EscapeSpecialCharacter(string argument) =>
: sb.Append(c),
static sb => sb.ToString());

static bool NeedsToBeEnclosedInDoubleQuotes(string argument)
=> argument.Any(c => c is ' ' or '\t' or ',' or ';' or '\u00FF' or '=' or '"')
|| argument.EndsWith("*") || argument.EndsWith(@"*""");
static bool NeedsToBeEnclosedInDoubleQuotes(string argument) =>
argument.Any(static c => c is ' ' or '\t' or ',' or ';' or '\u00FF' or '=' or '"')
|| argument.EndsWith("*");

static string EncloseInDoubleQuotes(string argument)
{
if (IsEnclosedInDoubleQuotes(argument))
{
// Remove any existing outer double quotes.
// Remove any existing outer double quotes. We add them back later.
argument = argument.Substring(1, argument.Length - 2);
}
// Any inline double quote need to escaped by doubling " -> ""
Expand Down

0 comments on commit dec8329

Please sign in to comment.