Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check that numeric value exists (#12042) (CP: 2.7) #12049

Merged
merged 1 commit into from
Oct 15, 2021
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
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