Skip to content

Commit 4f2ee8d

Browse files
committed
[MNG-7644] Fix version comparison ( .RC1 < -RC2 )
1 parent 7d45894 commit 4f2ee8d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,14 @@ else if ( Character.isDigit( c ) )
676676
{
677677
if ( !isDigit && i > startIndex )
678678
{
679+
// 1.0.0.RC1 < 1.0.0-RC2
680+
// treat .RC as -RC
681+
if ( !list.isEmpty() )
682+
{
683+
list.add( list = new ListItem() );
684+
stack.push( list );
685+
}
686+
679687
list.add( new StringItem( version.substring( startIndex, i ), true ) );
680688
startIndex = i;
681689

@@ -702,6 +710,14 @@ else if ( Character.isDigit( c ) )
702710

703711
if ( version.length() > startIndex )
704712
{
713+
// 1.0.0.RC1 < 1.0.0-RC2
714+
// treat .RC as -RC
715+
if ( !isDigit && !list.isEmpty() )
716+
{
717+
list.add( list = new ListItem() );
718+
stack.push( list );
719+
}
720+
705721
list.add( parseItem( isDigit, version.substring( startIndex ) ) );
706722
}
707723

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,12 @@ public void testReuse()
337337

338338
assertEquals( "reused instance should be equivalent to new instance", c1, c2 );
339339
}
340+
341+
/**
342+
* Test <a href="https://issues.apache.org/jira/browse/MNG-7644">MNG-7644</a> edge cases
343+
* 1.0.0.RC1 < 1.0.0-RC2
344+
*/
345+
public void testMng7644() {
346+
checkVersionsOrder( "1.0.0.RC1", "1.0.0-RC2" );
347+
}
340348
}

0 commit comments

Comments
 (0)