Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion opennlp-tools/src/main/java/opennlp/tools/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,14 @@ public static Version parse(String version) {
throw new NumberFormatException("Invalid version format '" + version + "', expected two dots!");
}

int indexThirdDot = version.indexOf('.', indexSecondDot + 1);
int indexFirstDash = version.indexOf('-');

int versionEnd;
if (indexFirstDash == -1) {
if (indexFirstDash == -1 && indexThirdDot == -1) {
versionEnd = version.length();
} else if (indexThirdDot != -1) {
versionEnd = indexThirdDot;
} else {
versionEnd = indexFirstDash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ void testParseSnapshot() {
Version.parse("1.5.2-SNAPSHOT"));
}

@Test
void testParseSuffixedVersion() {
Assertions.assertEquals(new Version(1, 5, 4, false),
Version.parse("1.5.4.foobar-007"));
Assertions.assertEquals(new Version(1, 5, 4, false),
Version.parse("1.5.4.foobar"));
}

@Test
void testParseProjectVersionWithRarePatchVersion() {
// A rare extra patch version is present (e.g., 2.5.6.1), which OpenNLP normally doesn't use.
Expand Down