Passing a provider-name-prefixed path to Set-Location makes $PWD retain the prefix
See original GitHub issuePerhaps related: #9293
Steps to reproduce
Run the following on Windows (works analogously on Unix):
Set-Location Microsoft.PowerShell.Core\FileSystem::C:\Windows
"$PWD" | Should -Be C:\Windows
Note: A real-life scenario in which this could occur is if you pipe the output from a New-Item -Type Directory
call to Set-Location
, e.g.:
New-Item -Type Directory $HOME -Force | Set-Location
Expected behavior
The test should pass.
Actual behavior
The test fails:
Expected strings to be the same, but they were different.
Expected length: 10
Actual length: 48
Strings differ at index 0.
Expected: 'C:\Windows'
But was: 'Microsoft....'
That is, $PWD
stringified (via .Path
) to 'Microsoft.PowerShell.Core\FileSystem::C:\Windows'
, not the expected C:\Windows
, as also reflected in the prompt string afterwards (via $executionContext.SessionState.Path.CurrentLocation
).
While $PWD.ProviderPath
does reflect the unprefixed (but always native) fileysystem path, relying on "$PWD"
or $PWD.Path
to do that too is very common.
Environment data
PowerShell Core 7.0.0-preview.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (9 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The @PowerShell/wg-powershell-cmdlets discussed this and since this is not a change in behavior and has existed for a long time, we recommend
Won't Fix
To quote from the OP, emphasis added:
I don’t think anyone expects - nor should they - that the way they specify the location determines how that location is reported.
E.g, if I do
Set-Location ./tmp
in order to change to, say,C:\foo\tmp
, I expect both the prompt string andGet-Location
to reflectC:\foo\tmp
, not./tmp
.The same applies to passing a provider-prefixed path: it is just a way to identify the target item on input, which is unrelated to the presentation on output, which should be standardized.
This is a breaking change in the same way that any bug fix is a breaking change: it corrects unexpected behavior.