Skip to content

Commit b5b15d7

Browse files
committed
[MNG-7644] Fix version comparison ( .RC1 < -RC2 )
1 parent 29f96a3 commit b5b15d7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,13 @@ public final void parseVersion(String version) {
570570
stack.push(list);
571571
} else if (Character.isDigit(c)) {
572572
if (!isDigit && i > startIndex) {
573+
// 1.0.0.RC1 < 1.0.0-RC2
574+
// treat .RC as -RC
575+
if (!list.isEmpty()) {
576+
list.add(list = new ListItem());
577+
stack.push(list);
578+
}
579+
573580
list.add(new StringItem(version.substring(startIndex, i), true));
574581
startIndex = i;
575582

@@ -592,6 +599,13 @@ public final void parseVersion(String version) {
592599
}
593600

594601
if (version.length() > startIndex) {
602+
// 1.0.0.RC1 < 1.0.0-RC2
603+
// treat .RC as -RC
604+
if (!isDigit && !list.isEmpty()) {
605+
list.add(list = new ListItem());
606+
stack.push(list);
607+
}
608+
595609
list.add(parseItem(isDigit, version.substring(startIndex)));
596610
}
597611

maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ private Comparable newComparable(String version) {
7171
};
7272

7373
private static final String[] VERSIONS_NUMBER = {
74-
"2.0", "2-1", "2.0.a", "2.0.0.a", "2.0.2", "2.0.123", "2.1.0", "2.1-a", "2.1b", "2.1-c", "2.1-1", "2.1.0.1",
75-
"2.2", "2.123", "11.a2", "11.a11", "11.b2", "11.b11", "11.m2", "11.m11", "11", "11.a", "11b", "11c", "11m"
74+
"2.0", "2.0.a", "2-1", "2.0.2", "2.0.123", "2.1.0", "2.1-a", "2.1b", "2.1-c", "2.1-1", "2.1.0.1", "2.2",
75+
"2.123", "11.a2", "11.a11", "11.b2", "11.b11", "11.m2", "11.m11", "11", "11.a", "11b", "11c", "11m"
7676
};
7777

7878
private void checkVersionsOrder(String[] versions) {
@@ -346,4 +346,14 @@ public void testReuse() {
346346

347347
assertEquals(c1, c2, "reused instance should be equivalent to new instance");
348348
}
349+
350+
/**
351+
* Test <a href="https://issues.apache.org/jira/browse/MNG-7644">MNG-7644</a> edge cases
352+
* 1.0.0.RC1 < 1.0.0-RC2
353+
*/
354+
@Test
355+
public void testMng7644() {
356+
checkVersionsOrder("1.0.0.RC1", "1.0.0-RC2");
357+
checkVersionsEqual("2.0.a", "2.0.0.a"); // previously ordered, now equals
358+
}
349359
}

0 commit comments

Comments
 (0)