-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Test-Path -IsValid -PathType Leaf doesn't correctly recognize a leaf #8607
Copy link
Copy link
Closed
Labels
Breaking-Changebreaking change that may affect usersbreaking change that may affect usersIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.The question is answered.Resolution-ExternalThe issue is caused by external component(s).The issue is caused by external component(s).WG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core modulecmdlets in the Microsoft.PowerShell.Core module
Metadata
Metadata
Assignees
Labels
Breaking-Changebreaking change that may affect usersbreaking change that may affect usersIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.The question is answered.Resolution-ExternalThe issue is caused by external component(s).The issue is caused by external component(s).WG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core modulecmdlets in the Microsoft.PowerShell.Core module
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.