You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/08/01 11:13:04 UTC

Re: [PR] fix #89: reconstruct baseUrl from URL components to avoid query/fragment corruption [maven-shared-io]

Copilot commented on code in PR #109:
URL: https://github.com/apache/maven-shared-io/pull/109#discussion_r3695494696


##########
src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.java:
##########
@@ -45,11 +45,15 @@
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import org.easymock.Capture;
+

Review Comment:
   Non-static imports are split into multiple groups and out of alphabetical order: `org.easymock.Capture` is separated from the other `org.*` imports (and comes after `org.junit.*`). Other tests keep all `org.*` imports together and sorted (e.g., `src/test/java/org/apache/maven/shared/io/logging/DefaultMessageHolderTest.java:24-25`). This may violate the project's import-order checks (spotless/checkstyle).



##########
src/main/java/org/apache/maven/shared/io/download/DefaultDownloadManager.java:
##########
@@ -115,8 +115,13 @@ public File download(String url, List<TransferListener> transferListeners, Messa
         messageHolder.addMessage("Download target is: " + downloaded.getAbsolutePath());
 
         // split the download URL into base URL and remote path for connecting, then retrieving.
+        // Build baseUrl from URL components to avoid corruption by query strings or fragments.
         String remotePath = sourceUrl.getPath();
-        String baseUrl = url.substring(0, url.length() - remotePath.length());
+        int port = sourceUrl.getPort();
+        String baseUrl = sourceUrl.getProtocol() + "://"
+                + (sourceUrl.getUserInfo() != null ? sourceUrl.getUserInfo() + "@" : "")
+                + sourceUrl.getHost()
+                + (port != -1 ? ":" + port : "");

Review Comment:
   `baseUrl` is now always built as `protocol + "://" + host...`, which changes behavior for non-authority URLs like `file:/tmp/x` (previously produced `file:` via substring) and produces invalid URLs for IPv6 literals (e.g., `http://[::1]/x` becomes `http://::1`). Using the URL authority component avoids query/fragment corruption while preserving existing `file:` vs `file://` behavior and correctly retains IPv6 brackets and userInfo/port.



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org