Do not reject Windows' reserved device names on non-Windows platforms. (#3252)
This commit is contained in:
parent
e734d44199
commit
97be759cc7
@ -1110,6 +1110,7 @@ namespace System.Management.Automation
|
||||
|
||||
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" };
|
||||
@ -1133,7 +1134,7 @@ namespace System.Management.Automation
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
|
||||
Describe "Basic FileSystem Provider Tests" -Tags "CI" {
|
||||
BeforeAll {
|
||||
$testDir = "TestDir"
|
||||
@ -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 {
|
||||
@ -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" {
|
||||
@ -667,4 +718,4 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur
|
||||
catch { $_.FullyQualifiedErrorId | Should Be "Argument,Microsoft.PowerShell.Commands.PopLocationCommand" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user