Powershell: `Split-Path /` should not throw error

Created on 10 Jul 2019  路  6Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

Split-Path /

Expected behavior

Empty string, like Split-Path C:

Actual behavior

Split-Path : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
At line:1 char:1
+ Split-Path /
+ ~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Split-Path], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.SplitPathCommand

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.1
OS                             Darwin 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Area-Cmdlets-Management Issue-Bug

Most helpful comment

@vors How strange. This only seems to happen in *nix systems. On Windows, (core or desktop) it quietly returns an empty string. This does seem like a bug.

All 6 comments

@vors How strange. This only seems to happen in *nix systems. On Windows, (core or desktop) it quietly returns an empty string. This does seem like a bug.

Ah interesting, didn't test it on windows.

Also occurs on 6.2.2

@SteveL-MSFT this could be a good hackathon candidate?

@TylerLeonhardt I suspect it's not going to be an easy fix as the FileSystemProvider special cases / as a root drive on Unix systems when most of the code expects a drive letter.

The same on Windows:

 Split-Path C:
Split-Path : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
At line:1 char:1
+ Split-Path C:
+ ~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Split-Path], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.SplitPathCommand

@TylerLeonhardt It seems ok for hackathon because we see the same behavior on all platforms for root.

Was this page helpful?
0 / 5 - 0 ratings