Skip to content

PathTool.getRelativeFilePath broken Windows drive letter regex #383

Description

@elharo

PathTool.getRelativeFilePath() has a broken regex for matching Windows drive letters at lines 146 and 149:

if (toPath.matches("^\\[a-zA-Z]:")) {
    toPath = toPath.substring(1);
}

The regex ^\\[a-zA-Z]: contains an erroneous \ before [, so instead of matching a backslash + drive letter (e.g. \C:), it matches the literal string [a-zA-Z]:. The intent was to match a leading backslash followed by a drive letter — paths like \C:\foo that File.getPath() can produce on Windows when given /C:/foo.

The correct regex should be ^\\\\[a-zA-Z]: which in a Java string becomes "^\\\\[a-zA-Z]:" — matching a literal backslash, a letter, and a colon at the start of the string.

This means the drive-letter normalization code is effectively dead on Windows, causing incorrect relative paths or null returns when paths have a leading separator before the drive letter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions