mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix WildcardPattern.Escape to escape lone backticks correctly (#25211)
This commit is contained in:
@@ -82,6 +82,21 @@ Describe "ComparisonOperator" -Tag "CI" {
|
||||
param($lhs, $operator, $rhs)
|
||||
Invoke-Expression "$lhs $operator $rhs" | Should -BeFalse
|
||||
}
|
||||
|
||||
It "Should be <result> for backtick comparison <lhs> <operator> <rhs>" -TestCases @(
|
||||
@{ lhs = 'abc`def'; operator = '-like'; rhs = 'abc`def'; result = $false }
|
||||
@{ lhs = 'abc`def'; operator = '-like'; rhs = 'abc``def'; result = $true }
|
||||
@{ lhs = 'abc`def'; operator = '-like'; rhs = 'abc````def'; result = $false }
|
||||
@{ lhs = 'abc``def'; operator = '-like'; rhs = 'abc````def'; result = $true }
|
||||
@{ 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 }
|
||||
) {
|
||||
param($lhs, $operator, $rhs, $result)
|
||||
$expression = "'$lhs' $operator '$rhs'"
|
||||
Invoke-Expression $expression | Should -Be $result
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Bytewise Operator" -Tag "CI" {
|
||||
|
||||
@@ -25,6 +25,22 @@ namespace PSTests.Parallel
|
||||
[InlineData("a", "a")]
|
||||
[InlineData("a*", "a`*")]
|
||||
[InlineData("*?[]", "`*`?`[`]")]
|
||||
[InlineData("`", "``")]
|
||||
[InlineData("```", "``````")]
|
||||
[InlineData("a`", "a``")]
|
||||
[InlineData("abc`def", "abc``def")]
|
||||
[InlineData("abc``def", "abc````def")]
|
||||
[InlineData("text with `backticks", "text with ``backticks")]
|
||||
[InlineData("ends with `", "ends with ``")]
|
||||
[InlineData("`starts with", "``starts with")]
|
||||
[InlineData("`in`between`", "``in``between``")]
|
||||
[InlineData("no special characters", "no special characters")]
|
||||
[InlineData("`*`", "```*``")]
|
||||
[InlineData("*`?[]", "`*```?`[`]")]
|
||||
[InlineData("`*`?`[", "```*```?```[")]
|
||||
[InlineData("*?[]`", "`*`?`[`]``")]
|
||||
[InlineData("nested `backticks `inside`", "nested ``backticks ``inside``")]
|
||||
[InlineData("wildcard*with`backtick", "wildcard`*with``backtick")]
|
||||
public void TestEscape_String(string source, string expected)
|
||||
{
|
||||
Assert.Equal(WildcardPattern.Escape(source), expected);
|
||||
|
||||
Reference in New Issue
Block a user