phaneendra-injarapu opened a new pull request, #109:
URL: https://github.com/apache/maven-shared-io/pull/109

   ## Summary
   
     Fixes #89
   
     ### Problem
   
     `DefaultDownloadManager.java` reconstructed the Wagon `baseUrl` by 
subtracting
     the length of the URL path from the end of the raw URL string:
   
     ```java
     // Before (buggy)
     String remotePath = sourceUrl.getPath();   // e.g. "/path/file.jar" — no 
query/fragment
     String baseUrl = url.substring(0, url.length() - remotePath.length());
   
     URL.getPath() correctly strips the query string and fragment, but the
     subtraction is applied against the full raw URL string which still carries
     those suffixes. The result is a truncated, invalid baseUrl:
   
     
┌─────────────────────────────────────┬─────────────────────────┬────────────────────────────┐
     │              Input URL              │       remotePath        │       
Buggy baseUrl        │
     
├─────────────────────────────────────┼─────────────────────────┼────────────────────────────┤
     │ http://host/path/file.jar?token=abc │ /path/file.jar (len 14) │ 
http://host/path/file.j ❌ │
     
├─────────────────────────────────────┼─────────────────────────┼────────────────────────────┤
     │ http://host/path/file.jar#section   │ /path/file.jar (len 14) │ 
http://host/path/file ❌   │
     
└─────────────────────────────────────┴─────────────────────────┴────────────────────────────┘
   
     This corrupts the Repository URL passed to wagon.connect(), breaking Wagon
     connectivity for any URL that contains query parameters or a fragment.
   
     Fix
   
     Reconstruct baseUrl explicitly from the java.net.URL object's own component
     fields — protocol, userInfo, host, and port. These fields are never
     contaminated by query strings or fragments:
   
     // After (correct)
     String remotePath = sourceUrl.getPath();
     int port = sourceUrl.getPort();
     String baseUrl = sourceUrl.getProtocol() + "://"
             + (sourceUrl.getUserInfo() != null ? sourceUrl.getUserInfo() + "@" 
: "")
             + sourceUrl.getHost()
             + (port != -1 ? ":" + port : "");
   
     Correct results for all URL forms:
   
     ┌─────────────────────────────────────┬────────────────────────┐
     │              Input URL              │      New baseUrl       │
     ├─────────────────────────────────────┼────────────────────────┤
     │ http://host/path/file.jarhttp://host ✅         │
     ├─────────────────────────────────────┼────────────────────────┤
     │ http://host/path/file.jar?token=abchttp://host ✅         │
     ├─────────────────────────────────────┼────────────────────────┤
     │ http://host/path/file.jar#sectionhttp://host ✅         │
     ├─────────────────────────────────────┼────────────────────────┤
     │ http://host:8080/path/file.jarhttp://host:8080 ✅    │
     ├─────────────────────────────────────┼────────────────────────┤
     │ http://user:pw@host/path/file.jarhttp://user:pw@host ✅ │
     ├─────────────────────────────────────┼────────────────────────┤
     │ file:///tmp/file.jar                │ file:// ✅             │
     └─────────────────────────────────────┴────────────────────────┘
   
     All pre-existing URL forms produce the same result as before — no behaviour
     change for plain URLs without query strings or fragments.
   
     Changes
   
     DefaultDownloadManager.java — replaced 1 line of string arithmetic with
     4-line component-based reconstruction (lines 117-124).
   
     DefaultDownloadManagerTest.java — added 2 regression tests using
     EasyMock's Capture<Repository> to assert that Repository.getUrl() equals
     exactly "http://example.com"; with no trailing path, query string, or 
fragment:
   
     - shouldUseCorrectBaseUrlWhenUrlHasQueryString — input: 
http://example.com/path/file.jar?token=abc
     - shouldUseCorrectBaseUrlWhenUrlHasFragment — input: 
http://example.com/path/file.jar#section
   
     All 16 tests pass (14 pre-existing + 2 new).


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