Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix WildcardPattern.Escape to escape lone backticks correctly#25211

Merged
iSazonov merged 8 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
ArmaanMcleod:fix-wildcard-escape-v2ArmaanMcleod/PowerShell:fix-wildcard-escape-v2Copy head branch name to clipboard
Mar 25, 2025
Merged

Fix WildcardPattern.Escape to escape lone backticks correctly#25211
iSazonov merged 8 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
ArmaanMcleod:fix-wildcard-escape-v2ArmaanMcleod/PowerShell:fix-wildcard-escape-v2Copy head branch name to clipboard

Conversation

@ArmaanMcleod

@ArmaanMcleod ArmaanMcleod commented Mar 22, 2025

Copy link
Copy Markdown
Contributor

PR Summary

Fix WildcardPattern.Escape to escape lone backticks correctly.

I have added the -like specific tests in Pester and the Escape() method conversion tests in XUnit.

Given backtick is included in SpecialChars which also has wildcard chars, it seems more straightforward to just do SpecialChars.Contains(ch) instead of IsWildcardChar(ch) || ch == escapeChar in the Escape() method.

PR Context

Fixes #16306

cc @IISResetMe

PR Checklist

@iSazonov iSazonov added CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log labels Mar 22, 2025
@ArmaanMcleod ArmaanMcleod changed the title Fix WildcardPattern.Escape for backticks Fix WildcardPattern.Escape to escape lone backticks correctly Mar 22, 2025
@{ lhs = 'abc`def'; operator = '-like'; rhs = [WildcardPattern]::Escape('abc`def'); result = $true }
@{ lhs = 'abc`def'; operator = '-like'; rhs = [WildcardPattern]::Escape('abc``def'); result = $false }
@{ lhs = 'abc``def'; operator = '-like'; rhs = [WildcardPattern]::Escape('abc``def'); result = $true }
@{ lhs = 'abc``def'; operator = '-like'; rhs = [WildcardPattern]::Escape('abc````def'); result = $false }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is "Win7 backcompatibility requires treating '`' pattern as '' pattern" comment in regex.cs file. Please add a test for the scenario.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iSazonov Do we need to worry about this? I am not sure why we are still trying to support Win 7 compatibility and why such code even exists 😄. Can you elaborate on what scenario this covers?

@ArmaanMcleod ArmaanMcleod Mar 22, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given also the code changes here are in Escape() I am not sure what I am testing. The Win7 compatibility is more with ensuring WildcardPattern in Parse() method treats lone backtick as empty string.

@iSazonov

Copy link
Copy Markdown
Collaborator

@IISResetMe Could you please review?

@iSazonov iSazonov self-assigned this Mar 22, 2025
@IISResetMe

Copy link
Copy Markdown
Collaborator

Changes look good to me!

@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@iSazonov iSazonov merged commit e308222 into PowerShell:master Mar 25, 2025
@microsoft-github-policy-service

microsoft-github-policy-service Bot commented Mar 25, 2025

Copy link
Copy Markdown
Contributor

📣 Hey @ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@ArmaanMcleod

Copy link
Copy Markdown
Contributor Author

Amazing. Thanks @iSazonov & @IISResetMe for the reviews and discussion on this one. It took a couple tries but I think we got there in the end 😄. Learnt a lot more how PowerShell does escaping internally too.

@iSazonov

Copy link
Copy Markdown
Collaborator

We are waiting feedback from community now. If there are no critical messages, then this will be included in the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WildcardPattern.Escape() does not escape lone backticks correctly

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.