Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3107,7 +3107,7 @@ protected override void ProcessRecord()
try
{
resolvedPSPaths = SessionState.Path.GetResolvedPSPathFromPSPath(path, currentContext);
if (null != LiteralPath && 0 == resolvedPSPaths.Count)
if (true == SuppressWildcardExpansion && 0 == resolvedPSPaths.Count)
{
ItemNotFoundException pathNotFound =
new ItemNotFoundException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,25 @@ Describe "Handling of globbing patterns" -Tags "CI" {
Copy-Item -LiteralPath $file.FullName -Destination $newPath
Test-Path -LiteralPath $newPath | Should Be $true
}
}

It "Remove-Item -LiteralPath should fail if it contains asterisk" {
Context "Handle asterisks in name" {
It "Remove-Item -LiteralPath should fail if it contains asterisk and file doesn't exist" {
{ Remove-Item -LiteralPath ./foo*.txt -ErrorAction Stop } | ShouldBeErrorId "PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand"
}

It "Remove-Item -LiteralPath should succeed for file with asterisk in name" -Skip:($IsWindows) {
$testPath = "$testdrive\foo*"
$testPath2 = "$testdrive\foo*2"
New-Item -Path $testPath -ItemType File
New-Item -Path $testPath2 -ItemType File
Test-Path -LiteralPath $testPath | Should Be $true
Test-Path -LiteralPath $testPath2 | Should Be $true
{ Remove-Item -LiteralPath $testPath } | Should Not Throw
Test-Path -LiteralPath $testPath | Should Be $false
# make sure wildcard wasn't applied so this file should still exist
Test-Path -LiteralPath $testPath2 | Should Be $true
}
}
}

Expand Down Expand Up @@ -989,7 +1004,7 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature

It "Verify Filter" {
Remove-Item "TestDrive:\*" -Filter "*.txt"
$result = Get-Item "*.txt"
$result = Get-Item "TestDrive:\*.txt"
$result | Should BeNullOrEmpty
}

Expand All @@ -1009,6 +1024,21 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature
$file1 | Should BeNullOrEmpty
$file2.Name | Should Be $testFile2
}

It "Verify Path can accept wildcard" {
Remove-Item "TestDrive:\*.txt" -Recurse -Force
$result = Get-ChildItem "TestDrive:\*.txt"
$result | Should BeNullOrEmpty
}

It "Verify no error if wildcard doesn't match: <path>" -TestCases @(
@{path="TestDrive:\*.foo"},
@{path="TestDrive:\[z]"},
@{path="TestDrive:\z.*"}
) {
param($path)
{ Remove-Item $path } | Should Not Throw
}
}

Context "Valdiate Set-Content parameters" {
Expand Down