gnodet commented on code in PR #387:
URL: https://github.com/apache/maven-filtering/pull/387#discussion_r4093528759


##########
src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java:
##########
@@ -181,10 +181,10 @@ public static String getRelativeFilePath(final String 
oldPath, final String newP
         String toPath = new File(newPath).getPath();
 
         // strip any leading slashes if its a windows path
-        if (toPath.matches("^\\[a-zA-Z]:")) {
+        if (toPath.matches("^[/\\\\][a-zA-Z]:.*")) {

Review Comment:
   Fixed in 87339db — tightened the regex to `^[/\\\\][a-zA-Z]:[/\\\\].*`, 
requiring a path separator immediately after the colon. This prevents false 
positives on Unix paths like `/a:/something` while still covering all valid 
Windows drive paths (`/C:/foo`, `\\C:\\foo`).



##########
src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java:
##########
@@ -146,4 +146,10 @@ void escapeWindowsPathNotAtBeginning() {
                 "jdbc:derby:C:\\\\Users\\\\Administrator/test;create=true",
                 
FilteringUtils.escapeWindowsPath("jdbc:derby:C:\\Users\\Administrator/test;create=true"));
     }
+
+    @Test
+    void relativeFilePathStripsLeadingSeparatorFromWindowsDrivePath() {
+        assertEquals("file.txt", FilteringUtils.getRelativeFilePath("C:/base", 
"/C:/base/file.txt"));
+        assertEquals("../other/file.txt", 
FilteringUtils.getRelativeFilePath("/C:/base/dir", "C:/base/other/file.txt"));

Review Comment:
   Fixed in 8c672d8 — normalized both `fromPath` and `toPath` with 
`.replace('\\\\', '/')` after `new File(path).getPath()`, then pass hardcoded 
`'/'` to `buildRelativePath`. The result now always uses forward slashes 
regardless of OS, so the test assertion is correct as-is.



-- 
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