elharo opened a new issue, #383:
URL: https://github.com/apache/maven-shared-utils/issues/383

   `PathTool.getRelativeFilePath()` has a broken regex for matching Windows 
drive letters at lines 146 and 149:
   
   ```java
   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to