Skip to content

Path normalization should not check drive letter on non-Windows #219

Description

@ForNeVeR

See this:

/// <summary>
/// Determines whether the specified source contains a drive letter.
/// </summary>
/// <param name="source">A read-only span of characters to be checked.</param>
/// <returns>
/// <c>true</c> if the source contains a drive letter (e.g., 'C:'); otherwise, <c>false</c>.
/// </returns>
private static bool SourceContainsDriveLetter(ReadOnlySpan<char> source)
{
if (source.Length < 2)
{
return false;
}
return source[1] == VolumeSeparatorChar && (uint)((source[0] | 0x20) - 'a') <= 'z' - 'a';
}

It seems this will break for paths like C:/ or /: on Unix.

Guard this per OS. Best of all, make the OS or bool checkDriveLetter a parameter, to keep the function behavior independent of OS.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions