elharo opened a new issue, #374:
URL: https://github.com/apache/maven-antrun-plugin/issues/374

   ## Summary
   `VersionMapper` both crashes and produces wrong results in edge cases:
   - `StringIndexOutOfBoundsException` when the version string is found at 
index 0 of the filename.
   - It removes the **first** occurrence of the version string, so when the 
version also appears inside the artifactId (or another segment), the wrong part 
of the filename is stripped.
   
   ## Affected code
   `src/main/java/org/apache/maven/ant/tasks/support/VersionMapper.java` lines 
40-56 (master @ `441382c`)
   
   ```java
   public String[] mapFileName(String sourceFileName) {
       String originalFileName = new File(sourceFileName).getName();
       for (String version : versions) {
           int index = originalFileName.indexOf(version);
           if (index >= 0) {
               String baseFilename = originalFileName.substring(0, index - 1);
               String extension = originalFileName.substring(index + 
version.length());
               ...
               return new String[] {path + baseFilename + extension};
           }
       }
       return new String[] {sourceFileName};
   }
   ```
   
   ## Reproduction (verified against the built artifact)
   - Version found at index 0: `setFrom("1.0")`, `mapFileName("1.0.jar")` →
     `StringIndexOutOfBoundsException: begin 0, end -1, length 7` (line 46, 
`substring(0, index - 1)` with `index == 0`).
   - Version occurring inside the artifactId: `setFrom("1.0")`, 
`mapFileName("a-1.0-b-1.0.jar")` → `a-b-1.0.jar`. The first occurrence (in the 
artifactId) is stripped instead of the trailing version suffix; the intended 
result is `a-1.0-b.jar`.
   
   ## Problem
   `indexOf` finds the first occurrence, not the trailing 
`-<version>(-<classifier>).<type>` segment the mapper is documented to strip. 
Combined with the unguarded `substring(0, index - 1)`, both a crash and silent 
wrong renames are possible.
   
   ## Expected behavior
   Match the version segment anchored to the trailing `-` (e.g. `-<version>` or 
`-<version>(-<classifier>)` before the extension), and guard against `index == 
0`.
   


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