@@ -605,11 +605,12 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
605
605
}
606
606
}
607
607
608
- $realFile = Join-Path $TestPath " file.txt"
608
+ # Ensure that the file link can still be successfully created when the target file/directory name contains wildcards.
609
+ $realFile = Join-Path $TestPath " [file].txt"
609
610
$nonFile = Join-Path $TestPath " not-a-file"
610
611
$fileContent = " some text"
611
- $realDir = Join-Path $TestPath " subdir"
612
- $realDir2 = Join-Path $TestPath " second-subdir"
612
+ $realDir = Join-Path $TestPath " [ subdir] "
613
+ $realDir2 = Join-Path $TestPath " [ second-subdir] "
613
614
$nonDir = Join-Path $TestPath " not-a-dir"
614
615
$hardLinkToFile = Join-Path $TestPath " hard-to-file.txt"
615
616
$symLinkToFile = Join-Path $TestPath " sym-link-to-file.txt"
@@ -626,7 +627,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
626
627
Context " New-Item and hard/symbolic links" {
627
628
AfterEach {
628
629
# clean up created links after each test
629
- Remove-Item - Exclude (Split-Path - Leaf $realFile , $realDir , $realDir2 ) - Recurse $TestPath /*
630
+ Remove-Item - Exclude (Split-Path - Leaf ([ WildcardPattern ]::Escape( $realFile )) , ([ WildcardPattern ]::Escape( $realDir )) , ([ WildcardPattern ]::Escape( $realDir2 )) ) - Recurse $TestPath /*
630
631
}
631
632
632
633
It " New-Item can create a hard link to a file" {
@@ -639,7 +640,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
639
640
It " New-Item can create symbolic link to file" {
640
641
New-Item - ItemType SymbolicLink - Path $symLinkToFile - Value $realFile > $null
641
642
Test-Path $symLinkToFile | Should - BeTrue
642
- $real = Get-Item - Path $realFile
643
+ $real = Get-Item - LiteralPath $realFile
643
644
$link = Get-Item - Path $symLinkToFile
644
645
$link.LinkType | Should - BeExactly " SymbolicLink"
645
646
$link.Target | Should - BeExactly $real.ToString ()
@@ -658,15 +659,15 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
658
659
It " New-Item can create a symbolic link to a directory" - Skip:($IsWindows ) {
659
660
New-Item - ItemType SymbolicLink - Path $symLinkToDir - Value $realDir > $null
660
661
Test-Path $symLinkToDir | Should - BeTrue
661
- $real = Get-Item - Path $realDir
662
+ $real = Get-Item - LiteralPath $realDir
662
663
$link = Get-Item - Path $symLinkToDir
663
664
$link.LinkType | Should - BeExactly " SymbolicLink"
664
665
$link.Target | Should - BeExactly $real.ToString ()
665
666
}
666
667
It " New-Item can create a directory symbolic link to a directory" - Skip:(-Not $IsWindows ) {
667
668
New-Item - ItemType SymbolicLink - Path $symLinkToDir - Value $realDir > $null
668
669
Test-Path $symLinkToDir | Should - BeTrue
669
- $real = Get-Item - Path $realDir
670
+ $real = Get-Item - LiteralPath $realDir
670
671
$link = Get-Item - Path $symLinkToDir
671
672
$link | Should - BeOfType System.IO.DirectoryInfo
672
673
$link.LinkType | Should - BeExactly " SymbolicLink"
@@ -677,7 +678,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
677
678
$target = Split-Path - Leaf $realDir
678
679
New-Item - ItemType SymbolicLink - Path $symLinkToDir - Value $target > $null
679
680
Test-Path $symLinkToDir | Should - BeTrue
680
- $real = Get-Item - Path $realDir
681
+ $real = Get-Item - LiteralPath $realDir
681
682
$link = Get-Item - Path $symLinkToDir
682
683
$link | Should - BeOfType System.IO.DirectoryInfo
683
684
$link.LinkType | Should - BeExactly " SymbolicLink"
@@ -689,7 +690,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
689
690
$target = " .\$ ( Split-Path - Leaf $realDir ) "
690
691
New-Item - ItemType SymbolicLink - Path $symLinkToDir - Value $target > $null
691
692
Test-Path $symLinkToDir | Should - BeTrue
692
- $real = Get-Item - Path $realDir
693
+ $real = Get-Item - LiteralPath $realDir
693
694
$link = Get-Item - Path $symLinkToDir
694
695
$link | Should - BeOfType System.IO.DirectoryInfo
695
696
$link.LinkType | Should - BeExactly " SymbolicLink"
@@ -732,8 +733,8 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
732
733
}
733
734
734
735
It " New-Item -Force can overwrite a junction" - Skip:(-Not $IsWindows ){
735
- $rd2 = Get-Item - Path $realDir2
736
- New-Item - Name testfile.txt - ItemType file - Path $realDir
736
+
F11C
$rd2 = Get-Item - LiteralPath $realDir2
737
+ New-Item - Name testfile.txt - ItemType file - Path ([ WildcardPattern ]::Escape( $realDir ))
737
738
New-Item - ItemType Junction - Path $junctionToDir - Value $realDir > $null
738
739
Test-Path $junctionToDir | Should - BeTrue
739
740
{ New-Item - ItemType Junction - Path $junctionToDir - Value $realDir - ErrorAction Stop > $null } | Should - Throw - ErrorId " DirectoryNotEmpty,Microsoft.PowerShell.Commands.NewItemCommand"
@@ -879,7 +880,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
879
880
880
881
Remove-Item - Path $Link - ErrorAction SilentlyContinue > $null
881
882
Test-Path - Path $Link | Should - BeFalse
882
- Test-Path - Path $Target | Should - BeTrue
883
+ Test-Path - LiteralPath $Target | Should - BeTrue
883
884
}
884
885
}
885
886
0 commit comments