ascheman commented on code in PR #287:
URL: 
https://github.com/apache/maven-remote-resources-plugin/pull/287#discussion_r3815861389


##########
src/main/java/org/apache/maven/plugin/resources/remote/ModelInheritanceAssembler.java:
##########
@@ -568,51 +569,34 @@ protected String appendPath(String parentPath, String 
childPath, String pathAdju
             uncleanPath = uncleanPath.substring(protocolIdx + 3);
         }
 
-        if (uncleanPath.startsWith("/")) {
-            cleanedPath += "/";
-        }
-
         return cleanedPath + resolvePath(uncleanPath);
     }
 
-    // TODO Move this to plexus-utils' PathTool.
-    private static String resolvePath(String uncleanPath) {
-        LinkedList<String> pathElements = new LinkedList<>();
-
-        StringTokenizer tokenizer = new StringTokenizer(uncleanPath, "/");
-
-        while (tokenizer.hasMoreTokens()) {
-            String token = tokenizer.nextToken();
-
-            switch (token) {
-                case "":
-                    // Empty path entry ("...//.."), remove.
-                    break;
-                case "..":
-                    if (pathElements.isEmpty()) {
-                        // FIXME: somehow report to the user
-                        // that there are too many '..' elements.
-                        // For now, ignore the extra '..'.
-                    } else {
-                        pathElements.removeLast();
-                    }
-                    break;
-                default:
-                    pathElements.addLast(token);
-                    break;
-            }
-        }
+    /**
+     * Normalizes the path part of an SCM URL using {@link 
java.nio.file.Path#normalize()}.
+     * <ul>
+     *   <li>Trailing separators are significant (e.g. {@code 
http://host/repo/} is not
+     *       {@code http://host/repo}) and are preserved.</li>
+     *   <li>Redundant separators, {@code "."} and resolvable {@code ".."} 
segments are collapsed.</li>
+     *   <li>Excess {@code ".."} segments that would climb above the path root 
are left to the
+     *       normalizer instead of being silently dropped.</li>
+     * </ul>
+     */
+    private String resolvePath(String uncleanPath) {
+        boolean trailingSeparator = uncleanPath.endsWith("/");
 
-        StringBuilder cleanedPath = new StringBuilder();
+        String resolved;
+        try {
+            resolved = 
Paths.get(uncleanPath).normalize().toString().replace(File.separatorChar, '/');

Review Comment:
   `java.nio.file.Paths` applies *filesystem* path rules, which are 
platform-dependent — so this normalizes SCM URLs differently across OSes. On 
Windows a segment containing `:` (a port, e.g. `host:8080/…`, common in SVN/git 
SCM URLs) is an illegal path and `Paths.get(...)` throws 
`InvalidPathException`, so the `catch` below returns the value 
**un-normalized**. The same input on Linux normalizes fine:
   
   ```
   host:8080/repo/../x  ->  host:8080/x                     (Linux)
   host:8080/repo/../x  ->  InvalidPathException, unchanged (Windows)
   ```
   
   That reintroduces exactly the cross-platform inconsistency #274 is about. A 
pure-string normalizer (or `java.net.URI`) would fix the edge cases without 
coupling to filesystem rules.
   



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