[MNG-7106] Accept same lower and upper bound in version spec string (#825)

This commit is contained in:
Konrad Windszus 2022-10-13 15:29:50 +02:00 committed by GitHub
parent 3f90e7028e
commit 78edd43122
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -211,10 +211,6 @@ public class VersionRange
{
String lowerBound = process.substring( 0, index ).trim();
String upperBound = process.substring( index + 1 ).trim();
if ( lowerBound.equals( upperBound ) )
{
throw new InvalidVersionSpecificationException( "Range cannot have identical boundaries: " + spec );
}
ArtifactVersion lowerVersion = null;
if ( lowerBound.length() > 0 )
@ -227,9 +223,13 @@ public class VersionRange
upperVersion = new DefaultArtifactVersion( upperBound );
}
if ( upperVersion != null && lowerVersion != null && upperVersion.compareTo( lowerVersion ) < 0 )
if ( upperVersion != null && lowerVersion != null )
{
throw new InvalidVersionSpecificationException( "Range defies version ordering: " + spec );
int result = upperVersion.compareTo( lowerVersion );
if ( result < 0 || ( result == 0 && ( !lowerBoundInclusive || !upperBoundInclusive ) ) )
{
throw new InvalidVersionSpecificationException( "Range defies version ordering: " + spec );
}
}
restriction = new Restriction( lowerVersion, lowerBoundInclusive, upperVersion, upperBoundInclusive );

View File

@ -160,6 +160,14 @@ public class VersionRangeTest
assertTrue( range.containsVersion( new DefaultArtifactVersion( "5.0.9.0" ) ) );
}
@Test
public void testSameUpperAndLowerBoundRoundtrip() throws InvalidVersionSpecificationException
{
VersionRange range = VersionRange.createFromVersionSpec( "[1.0]" );
VersionRange range2 = VersionRange.createFromVersionSpec( range.toString() );
assertEquals( range, range2 );
}
@Test
public void testInvalidRanges()
{