|
public static bool PowerShellArgumentNeedsEscaping(string argument) |
|
{ |
|
foreach (char c in argument) |
|
{ |
|
switch (c) |
|
{ |
|
case '\'': |
|
case '"': |
|
case '|': |
|
case '&': |
|
case ';': |
|
case ':': |
|
case char w when char.IsWhiteSpace(w): |
|
return true; |
|
} |
|
} |
|
|
Will match true on 'test string', it should match false. The ' case needs an additional check to make sure the argument isn't already enclosed in quotes.
PowerShellEditorServices/src/PowerShellEditorServices/Utility/StringEscaping.cs
Lines 17 to 33 in 8c568bc
Will match true on
'test string', it should match false. The ' case needs an additional check to make sure the argument isn't already enclosed in quotes.