New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test-Path -IsValid -PathType Leaf doesn't correctly recognize a leaf #8607
Comments
|
Hi @fullenw1 There are a couple of things to be aware of here. First, if PSCore > Test-Path -IsValid foo -PathType leaf
True
PSCore > Test-Path -IsValid foo -PathType Container
TrueSecond, when it is used by itself, PSCore > test-path -PathType Container $profile/
False
PSCore > test-path -PathType Leaf $profile/
TrueLikewise, when using the PSCore > Split-Path -Leaf a\b\c\
cArguably |
|
Thank you for the explanation. The breaking change (puting them in separate parameter sets) in the next version would probably be the logical way to go. |
|
For future breaking change reference #6745 |
|
@fullenw1 Please open issue in PowerShell-Docs repo. |
|
I have created pull request #3537 in the PowerShell-Docs repository. |
|
Close until we want the breaking change |
This issue is about an incorrect validation of the
Test-Pathcmdlet.When a path ends with a backslash it is supposed to be a container.
Furthermore, according to the official documentation:
and also
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-path?view=powershell-6
However, when using the
-IsValidparameter combined to the-PathType Leafparameter in order to validate the syntax of a file path, it is incorrectly validated as a leaf.For example, the following command line returns
$trueinstead of$false.PS C:\> Test-Path -IsValid -PathType Leaf -Path 'C:\Something\'TruePS C:\>It should return false because a leaf path cannot end with a backslash.
This behavior has been tested on PowerShell 5.1 and 6.1.1.
The text was updated successfully, but these errors were encountered: