From 9ab19079a4b9c294bb373df9e2e04c4f69b114f0 Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Sun, 14 Jun 2020 20:56:50 +0200 Subject: [PATCH 1/5] QUALIFIER for SPLIT-PATH should not be positional The syntax ``SPLIT-PATH C: $NULL`` is confusing and should not be supported. --- .../commands/management/ParsePathCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs index 0cf95e8ac9d..4efbd7ecb3b 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs @@ -107,7 +107,7 @@ public string[] LiteralPath /// The qualifier is the drive or provider that is qualifying /// the MSH path. /// - [Parameter(Position = 1, ValueFromPipelineByPropertyName = true, ParameterSetName = qualifierSet, Mandatory = false)] + [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = qualifierSet, Mandatory = false)] public SwitchParameter Qualifier { get; set; } /// From 1d74f7db763494bcbc26cfe1844c21b65f01d585 Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Sun, 14 Jun 2020 21:27:11 +0200 Subject: [PATCH 2/5] =?UTF-8?q?Verify=20SPLIT-PATH=20errors=20given=20para?= =?UTF-8?q?meter=C2=A0#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As of PowerShell 7.0.2, positional parameter #2 was treated by ``SPLIT-PATH`` as a value for QUALIFIER. --- .../Microsoft.PowerShell.Management/Split-Path.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 index ed524c5aa9d..acb4827253b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 @@ -29,6 +29,10 @@ Describe "Split-Path" -Tags "CI" { { Split-Path -Qualifier -ErrorAction Stop abcdef } | Should -Throw } + It "Should error given positional parameter #2" { + { Split-Path env: $NULL } | Should -Throw + } + It "Should return the path when the noqualifier switch is used" { Split-Path env:PATH -NoQualifier | Should -BeExactly "PATH" } From 075f6c9abb078ff4246f1119b5041ababbae5ede Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Mon, 15 Jun 2020 09:26:58 +0200 Subject: [PATCH 3/5] Parameters are not mandatory by default. Co-authored-by: Ilya --- .../commands/management/ParsePathCommand.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs index 4efbd7ecb3b..5e0711e55fa 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ParsePathCommand.cs @@ -107,7 +107,7 @@ public string[] LiteralPath /// The qualifier is the drive or provider that is qualifying /// the MSH path. /// - [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = qualifierSet, Mandatory = false)] + [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = qualifierSet)] public SwitchParameter Qualifier { get; set; } /// @@ -476,4 +476,3 @@ private string RemoveQualifier(string path) } } } - From 05558f92ccb61554a953e8e80bf53f737311bdb8 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 15 Jun 2020 10:54:52 -0700 Subject: [PATCH 4/5] Fix indentation of the new code --- .../Microsoft.PowerShell.Management/Split-Path.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 index acb4827253b..cd2332f1969 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Split-Path" -Tags "CI" { } It "Should error given positional parameter #2" { - { Split-Path env: $NULL } | Should -Throw + { Split-Path env: $NULL } | Should -Throw } It "Should return the path when the noqualifier switch is used" { From 9e4182f2f3505e7cf68d42fe64c3619ff8c73ebc Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Mon, 15 Jun 2020 22:03:29 +0200 Subject: [PATCH 5/5] Add ErrorId to test against positional parameter --- .../Microsoft.PowerShell.Management/Split-Path.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 index cd2332f1969..b9537a4a961 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Split-Path.Tests.ps1 @@ -30,7 +30,7 @@ Describe "Split-Path" -Tags "CI" { } It "Should error given positional parameter #2" { - { Split-Path env: $NULL } | Should -Throw + { Split-Path env: $NULL } | Should -Throw -ErrorId 'PositionalParameterNotFound,Microsoft.PowerShell.Commands.SplitPathCommand' } It "Should return the path when the noqualifier switch is used" {