Skip to content
Merged
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 @@ -9,6 +9,7 @@
using System.Management.Automation.Internal;
using System.Reflection;
using Dbg = System.Management.Automation;
using System.IO;

#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
#pragma warning disable 56500
Expand Down Expand Up @@ -3689,10 +3690,17 @@ internal void NewItem(

foreach (string path in paths)
{
string resolvePath = null;
if (path == null)
{
PSTraceSource.NewArgumentNullException("paths");
}
else
{
// To be compatible with Linux OS. Which will be either '/' or '\' depends on the OS type.
char[] charsToTrim = {' ', Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar};
resolvePath = path.TrimEnd(charsToTrim);
}

ProviderInfo provider = null;
PSDriveInfo driveInfo;
Expand All @@ -3705,7 +3713,7 @@ internal void NewItem(
if (String.IsNullOrEmpty(name))
{
string providerPath =
Globber.GetProviderPath(path, context, out provider, out driveInfo);
Globber.GetProviderPath(resolvePath, context, out provider, out driveInfo);

providerInstance = GetProviderInstance(provider);
providerPaths.Add(providerPath);
Expand All @@ -3714,7 +3722,7 @@ internal void NewItem(
{
providerPaths =
Globber.GetGlobbedProviderPathsFromMonadPath(
path,
resolvePath,
true,
context,
out provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,10 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') {
$_.FullyQualifiedErrorId | Should Be "NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand"
}
}

It "New-Item -ItemType SymbolicLink should understand directory path ending with slash" {
$folderName = [System.IO.Path]::GetRandomFileName()
$symbolicLinkPath = New-Item -ItemType SymbolicLink -Path "$tmpDirectory/$folderName/" -Value "/bar/"
$symbolicLinkPath | Should Not Be $null
}
}