KEMBAR78
WildcardPattern.Escape() does not escape lone backticks correctly · Issue #16306 · PowerShell/PowerShell · GitHub
Skip to content

WildcardPattern.Escape() does not escape lone backticks correctly #16306

@IISResetMe

Description

@IISResetMe

Prerequisites

Steps to reproduce

WildcardPattern.Escape() does not escape `, and as a result it's unreliable for escaping input for use in wildcard comparisons:

Define a string literal containing a single backtick character:

$string = 'abc`def'

Create an escaped copy of the string value:

$escaped = [WildcardPattern]::Escape($string)

Perform wildcard comparison and observe that it does not yield $true as expected:

$string -like $escaped

(That is: [WildcardPattern]::Escape($string) should produce a string value equivalent to 'abc``def', not return it as-is)

Expected behavior

PS> $string -like $escaped
True

Actual behavior

PS> $string -like $escaped
False

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aNeeds-InvestigationThe behavior reported in the issue is unexpected and needs further investigation.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions