elharo opened a new pull request, #380: URL: https://github.com/apache/maven-antrun-plugin/pull/380
## Fixes https://github.com/apache/maven-antrun-plugin/issues/374 ## Summary `VersionMapper.mapFileName` had two bugs: 1. When the version was found at index 0 of the filename, `substring(0, index - 1)` threw a `StringIndexOutOfBoundsException` (e.g. `setFrom("1.0")`, `mapFileName("1.0.jar")`). 2. `indexOf` matched the **first** occurrence of the version string, so a version appearing inside the artifactId was stripped instead of the trailing version segment (e.g. `a-1.0-b-1.0.jar` mapped to `a-b-1.0.jar` instead of `a-1.0-b.jar`). A version-like substring not at a segment boundary was also stripped (e.g. `a-1.0b.jar` → `ab.jar`). The mapper now anchors the match to a trailing `-<version>` segment: it searches for `-<version>` from the end of the filename and only strips when the version is followed by the file extension (`.`), a `-<classifier>` segment, or nothing. Because the match always includes the leading `-`, the index-0 crash is impossible and the version is no longer stripped from the middle of the artifact id. ## Changes - `VersionMapper.java`: replace the unanchored `indexOf` + `substring(0, index - 1)` with a `lastIndexOf('-' + version)` loop that validates the trailing segment boundary. - New unit test `VersionMapperTest` covering the basic case, classifier handling, the index-0 crash, the wrong-occurrence stripping, the non-boundary substring, directory preservation, and the no-match case. ## Verification - The new tests fail on master (StringIndexOutOfBoundsException and wrong stripped filenames) and pass with the fix. - `mvn verify` (rat, checkstyle, spotless, unit tests, javadoc) passes. - `mvn verify -Prun-its` passes: all 29 integration tests succeed. -- 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]
