Skip to content

Passing a provider-name-prefixed path to Set-Location makes $PWD retain the prefix #10522

@mklement0

Description

@mklement0

Perhaps 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions