Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 69cbcb3

Browse files
JeremyKuhnejkotas
authored andcommitted
Fix short path expansion (dotnet/coreclr#16901)
Also make methods internal so I can add better unit tests. Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
1 parent bf36018 commit 69cbcb3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Common/src/CoreLib/System/IO/PathHelper.Windows.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private static void GetFullPathName(string path, ref ValueStringBuilder builder)
6767
builder.Length = (int)result;
6868
}
6969

70-
private static int PrependDevicePathChars(ref ValueStringBuilder content, bool isDosUnc, ref ValueStringBuilder buffer)
70+
internal static int PrependDevicePathChars(ref ValueStringBuilder content, bool isDosUnc, ref ValueStringBuilder buffer)
7171
{
7272
int length = content.Length;
7373

@@ -98,7 +98,7 @@ private static int PrependDevicePathChars(ref ValueStringBuilder content, bool i
9898
}
9999
}
100100

101-
private static string TryExpandShortFileName(ref ValueStringBuilder outputBuilder, string originalPath)
101+
internal static string TryExpandShortFileName(ref ValueStringBuilder outputBuilder, string originalPath)
102102
{
103103
// We guarantee we'll expand short names for paths that only partially exist. As such, we need to find the part of the path that actually does exist. To
104104
// avoid allocating like crazy we'll create only one input array and modify the contents with embedded nulls.
@@ -197,13 +197,13 @@ private static string TryExpandShortFileName(ref ValueStringBuilder outputBuilde
197197
outputBuilder.Length = checked((int)result);
198198
if (foundIndex < inputLength - 1)
199199
{
200-
// It was a partial find, put the non-existent part of the path back
201-
outputBuilder.Append(inputBuilder.AsSpan(foundIndex, inputBuilder.Length - foundIndex));
200+
// It was a partial find, put the non-existent part of the path back (minus the added null)
201+
outputBuilder.Append(inputBuilder.AsSpan(foundIndex, inputBuilder.Length - foundIndex - 1));
202202
}
203203
}
204204
}
205205

206-
// Need to trim out the trailing separator in the input builder
206+
// Need to trim out the trailing null in the input builder
207207
inputBuilder.Length = inputBuilder.Length - 1;
208208

209209
// If we were able to expand the path, use it, otherwise use the original full path result

0 commit comments

Comments
 (0)