Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--********************************************************************/

using System;
using System.Text;
using System.Collections.ObjectModel;
using System.Management.Automation;
using Dbg = System.Management.Automation;
Expand Down Expand Up @@ -32,7 +33,17 @@ public class JoinPathCommand : CoreCommandWithCredentialsBase
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true)]
[AllowNull]
[AllowEmptyString]
public string ChildPath { get; set; } = String.Empty;
public string ChildPath { get; set; }

/// <summary>
/// Gets or sets additional childPaths to the command.
/// </summary>

[Parameter(Position = 2, Mandatory = false, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = true)]
[AllowNull]
[AllowEmptyString]
[AllowEmptyCollection]
public string[] AdditionalChildPath { get; set; } = Utils.EmptyArray<string>();

/// <summary>
/// Determines if the path should be resolved after being joined
Expand All @@ -55,6 +66,17 @@ protected override void ProcessRecord()
Path != null,
"Since Path is a mandatory parameter, paths should never be null");

string combinedChildPath = ChildPath;

// join the ChildPath elements
if (AdditionalChildPath != null)
{
foreach (string childPath in AdditionalChildPath)
{
combinedChildPath = SessionState.Path.Combine(combinedChildPath, childPath, CmdletProviderContext);
}
}

foreach (string path in Path)
{
// First join the path elements
Expand All @@ -64,7 +86,7 @@ protected override void ProcessRecord()
try
{
joinedPath =
SessionState.Path.Combine(path, ChildPath, CmdletProviderContext);
SessionState.Path.Combine(path, combinedChildPath, CmdletProviderContext);
}
catch (PSNotSupportedException notSupported)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ Describe "Join-Path cmdlet tests" -Tags "CI" {
$result.Count | Should be 1
$result | Should BeExactly ("Env:"+$SepChar+"foo")
}
It "should be able to join multiple child paths passed by position with remaining arguments" {
$result = Join-Path one two three four five
$result.Count | Should Be 1
$result | Should BeExactly "one${sepChar}two${sepChar}three${sepChar}four${sepChar}five"
}
}