diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs index bdeef0dd7a..71ef5df8f0 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs @@ -32,7 +32,8 @@ namespace Microsoft.PowerShell.Commands [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true)] [AllowNull] [AllowEmptyString] - public string ChildPath { get; set; } + [AllowEmptyCollection] + public string[] ChildPath { get; set; } /// /// Gets or sets additional childPaths to the command. @@ -64,7 +65,15 @@ namespace Microsoft.PowerShell.Commands Path != null, "Since Path is a mandatory parameter, paths should never be null"); - string combinedChildPath = ChildPath; + string combinedChildPath = string.Empty; + + if (this.ChildPath != null) + { + foreach (string childPath in this.ChildPath) + { + combinedChildPath = SessionState.Path.Combine(combinedChildPath, childPath, CmdletProviderContext); + } + } // join the ChildPath elements if (AdditionalChildPath != null) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 index 8cb6391cd7..a66bddd5e4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 @@ -50,4 +50,38 @@ Describe "Join-Path cmdlet tests" -Tags "CI" { $result.Count | Should -Be 1 $result | Should -BeExactly "one${sepChar}two${sepChar}three${sepChar}four${sepChar}five" } + It "Join-Path -Path -ChildPath should return ''" -TestCases @( + @{ + Path = 'one' + ChildPath = 'two', 'three' + ExpectedResult = "one${sepChar}two${sepChar}three" + } + @{ + Path = 'one', 'two' + ChildPath = 'three', 'four' + ExpectedResult = @( + "one${sepChar}three${sepChar}four" + "two${sepChar}three${sepChar}four" + ) + } + @{ + Path = 'one' + ChildPath = @() + ExpectedResult = "one${sepChar}" + } + @{ + Path = 'one' + ChildPath = $null + ExpectedResult = "one${sepChar}" + } + @{ + Path = 'one' + ChildPath = [string]::Empty + ExpectedResult = "one${sepChar}" + } + ) { + param($Path, $ChildPath, $ExpectedResult) + $result = Join-Path -Path $Path -ChildPath $ChildPath + $result | Should -BeExactly $ExpectedResult + } }