Skip to content

Commit

Permalink
fix: check that numeric value exists (#12042)
Browse files Browse the repository at this point in the history
Check that a value exists for buildIdentifier
before parsing integer.

Fixes #12041
  • Loading branch information
caalador authored Oct 15, 2021
1 parent 222a793 commit d0ce1ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ private int compareBuildIdentifier(FrontendVersion other) {
return thisMatcher.group(1)
.compareToIgnoreCase(otherMatcher.group(1));
}
// if one or both are missing numeric value do not parse int
if (thisMatcher.group(2).isEmpty()
|| otherMatcher.group(2).isEmpty()) {
return buildIdentifier
.compareToIgnoreCase(other.buildIdentifier);
}
return Integer.parseInt(thisMatcher.group(2))
- Integer.parseInt(otherMatcher.group(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Assert;
import org.junit.Test;

import static com.helger.commons.mock.CommonsAssert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -77,6 +78,18 @@ public void testIsEqualTo() {
fromString.isEqualTo(fromConstructor));
}

@Test // #12041
public void testSimilarBuildIdentifiers() {
FrontendVersion version = new FrontendVersion("1.1.1-SNAPSHOT");
FrontendVersion equals = new FrontendVersion("1.1.1-SNAPSHOT");

assertTrue("Versions be the same", version.isEqualTo(equals));
assertFalse("Version should not be older", version.isOlderThan(equals));
assertEquals("Versions should not have a difference", 0,
version.compareTo(equals));
assertFalse("Version should not be newer", version.isNewerThan(equals));
}

@Test(expected = NumberFormatException.class)
public void faultyStringVersion_throwsException() {
new FrontendVersion("12.0b.1");
Expand Down

0 comments on commit d0ce1ab

Please sign in to comment.