Skip to content

Commit e302ab5

Browse files
nohwndCopilot
andcommitted
Fix #2628: Should -Exist uses -LiteralPath for paths with wildcard characters
Copilot-generated fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d5f7c87 commit e302ab5

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/functions/assertions/Exist.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
`Should -Exist` calls Test-Path. Test-Path expects a file,
1313
returns $false because the file was removed, and fails the test.
1414
#>
15-
[bool] $succeeded = & $SafeCommands['Test-Path'] $ActualValue
15+
[bool] $succeeded = & $SafeCommands['Test-Path'] -LiteralPath $ActualValue
1616

1717
if ($Negate) {
1818
$succeeded = -not $succeeded

tst/functions/assertions/Exist.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ InPesterModuleScope {
1111
"TestDrive:\nonexistant" | Should -Not -Exist
1212
}
1313

14-
It 'works for path with escaped [ ] characters' {
14+
It 'works for path with literal [ ] characters' {
1515
New-Item -Path "TestDrive:\[test].txt" -ItemType File | Out-Null
16-
"TestDrive:\``[test``].txt" | Should -Exist
16+
"TestDrive:\[test].txt" | Should -Exist
1717
}
1818

1919
It 'returns correct result for function drive' {

0 commit comments

Comments
 (0)