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
3 changes: 2 additions & 1 deletion src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ internal static void NativeEnumerateDirectory(string directory, out List<string>

internal static bool IsReservedDeviceName(string destinationPath)
{
#if !UNIX
string[] reservedDeviceNames = { "CON", "PRN", "AUX", "CLOCK$", "NUL",
"COM0", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT0", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };
Expand All @@ -1133,7 +1134,7 @@ internal static bool IsReservedDeviceName(string destinationPath)
return true;
}
}

#endif
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
Describe "Basic FileSystem Provider Tests" -Tags "CI" {
BeforeAll {
$testDir = "TestDir"
Expand All @@ -20,6 +21,9 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
$newTestFile = "NewTestFile.txt"
$testContent = "Some Content"
$testContent2 = "More Content"
$reservedNames = "CON", "PRN", "AUX", "CLOCK$", "NUL",
"COM0", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT0", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
}

BeforeEach {
Expand Down Expand Up @@ -103,6 +107,53 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
$contentBefore.Count | Should Be 1
$contentAfter.Count | Should Be 0
}

It "Copy-Item on Windows rejects Windows reserved device names" -Skip:(-not $IsWindows) {
foreach ($deviceName in $reservedNames)
{
{ Copy-Item -Path $testFile -Destination $deviceName -ErrorAction Stop } | ShouldBeErrorId "CopyError,Microsoft.PowerShell.Commands.CopyItemCommand"
}
}

It "Move-Item on Windows rejects Windows reserved device names" -Skip:(-not $IsWindows) {
foreach ($deviceName in $reservedNames)
{
{ Move-Item -Path $testFile -Destination $deviceName -ErrorAction Stop } | ShouldBeErrorId "MoveError,Microsoft.PowerShell.Commands.MoveItemCommand"
}
}

It "Rename-Item on Windows rejects Windows reserved device names" -Skip:(-not $IsWindows) {
foreach ($deviceName in $reservedNames)
{
{ Rename-Item -Path $testFile -NewName $deviceName -ErrorAction Stop } | ShouldBeErrorId "RenameError,Microsoft.PowerShell.Commands.RenameItemCommand"
}
}

It "Copy-Item on Unix succeeds with Windows reserved device names" -Skip:($IsWindows) {
foreach ($deviceName in $reservedNames)
{
Copy-Item -Path $testFile -Destination $deviceName -Force -ErrorAction SilentlyContinue
Test-Path $deviceName | Should Be $true
}
}

It "Move-Item on Unix succeeds with Windows reserved device names" -Skip:($IsWindows) {
foreach ($deviceName in $reservedNames)
{
Move-Item -Path $testFile -Destination $deviceName -Force -ErrorAction SilentlyContinue
Test-Path $deviceName | Should Be $true
New-Item -Path $testFile -ItemType File -Force -ErrorAction SilentlyContinue
}
}

It "Rename-Item on Unix succeeds with Windows reserved device names" -Skip:($IsWindows) {
foreach ($deviceName in $reservedNames)
{
Rename-Item -Path $testFile -NewName $deviceName -Force -ErrorAction SilentlyContinue
Test-Path $deviceName | Should Be $true
New-Item -Path $testFile -ItemType File -Force -ErrorAction SilentlyContinue
}
}
}

Context "Validate basic host navigation functionality" {
Expand Down Expand Up @@ -667,4 +718,4 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur
catch { $_.FullyQualifiedErrorId | Should Be "Argument,Microsoft.PowerShell.Commands.PopLocationCommand" }
}
}
}
}