-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Note:
-
This is technically a breaking change, but one that to me falls into Bucket 3: Unlikely Grey Area.
-
We've recently made an analogous change to
Invoke-WebRequest/Invoke-RestMethod, which now sensibly interpret their-OutFileargument invariably as a literal path - see Make-OutFileparam in web cmdlets to work like -LiteralPath #11701- Similar fixes are pending in other contexts: Some scripts / files with wildcard metacharacter [ in the file name or path cannot be invoked or redirected to #4726, Namespace variable notation unexpectedly treats paths as wildcard expressions #9225, Some scripts / files with wildcard metacharacter [ in the file name or path cannot be invoked or redirected to #4726.
Summary of the new feature/enhancement
When you create a symlink or reparse point, you want to target a specific, literal target path - you're not looking for this path to determined via wildcard-pattern matching, which, however, is what currently happens: a -Target (-Value) argument is (invariably) interpreted as a wildcard pattern. What makes the behavior even less useful is that the pattern must resolve to exactly one path.
-
Interpreting the
-Target(-Value) argument as a wildcard expression means that meant-to-be-literal paths such as[a].txtwould mistakenly targeta.txt, if present, for instance. -
Also, as a potentially unwanted side effect, if the
-Target(-Value) is determined via wildcard resolution, a relative input path (pattern) is invariably resolved to a full path.
The sensible behavior is to always treat the -Target (-Value) argument as a literal path (and to preserve its relative-vs.-full path status, as specified).
Once the change is implemented, the following tests - which currently fail - should succeed:
$null = New-Item 'file1', 'file[1]'
$targetRelative = 'file[1]'
$targetAbsolute = Join-Path $pwd.providerpath 'file[1]'
(New-Item -Type SymbolicLink fileL -Target $targetRelative).Target | Should -Be $targetRelative
(New-Item -Force -Type SymbolicLink fileL -Target $targetAbsolute).Target | Should -Be $targetAbsoluteThe tests currently fail, because file[1] is interpreted as a wildcard pattern that happens to match file1.