-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Milestone
Description
While working on this issue (PR), I found a bug in the string overload for Path.GetPathRoot (Unix):
using System;
using System.IO;
namespace ConsoleAppCore
{
class Program
{
static void Main()
{
string original = "/home/../folder/../..";
string expected = "/";
ReadOnlySpan<char> actualSpan = Path.GetPathRoot(original.AsSpan());
string actualString = Path.GetPathRoot(original);
Console.WriteLine($"Expected: '{expected}'");
Console.WriteLine($"Actual string: '{actualString}'"); // This returns '/'
Console.WriteLine($"Actual span: '{actualSpan.ToString()}'"); // This returns ''
}
}
}I also found that running the same code in Windows will yield the behavior below, which is why I originally opened this issue, but @jkotas kindly pointed out it's expected behavior - the string method overload normalizes, while the span overload does not:
Console.WriteLine($"Actual span: '{actualSpan.ToString()}'"); // This returns '/'
Console.WriteLine($"Actual string: '{actualString}'"); // This returns '\'