Skip to content

PowershellArgumentNeedsEscaping does not account for a single quoted string #1608

Closed
@JustinGrote

Description

@JustinGrote

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions