Skip to content

Commit

Permalink
Fix "2.x" not appending an empty build version to the resulting predi…
Browse files Browse the repository at this point in the history
…cate. (#425)

This used to turn "2.x" or "=2.x" into "^2-", however a while ago this accidently got changed to "^2".

Honestly, I'm unsure which way is correct. However this was changed accidently during our Version.Sementic switching to non-null build & pre-release, so it's been changed back.
  • Loading branch information
AlexIIL committed Apr 23, 2024
1 parent efeec0a commit a4118a0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public SemanticVersion minVersion(SemanticVersion version) {
public SemanticVersion maxVersion(SemanticVersion version) {
int[] components = { version.getVersionComponent(0), version.getVersionComponent(1) + 1 };
try {
return Quilt2FabricSemanticVersion.toFabric(org.quiltmc.loader.api.Version.Semantic.of(components, "", ""));
return Quilt2FabricSemanticVersion.toFabric(org.quiltmc.loader.api.Version.Semantic.of(components, "", null));
} catch (VersionFormatException e) {
throw new IllegalStateException(e);
}
Expand All @@ -124,7 +124,7 @@ public SemanticVersion minVersion(SemanticVersion version) {
public SemanticVersion maxVersion(SemanticVersion version) {
int[] components = { version.getVersionComponent(0) + 1 };
try {
return Quilt2FabricSemanticVersion.toFabric(org.quiltmc.loader.api.Version.Semantic.of(components, "", ""));
return Quilt2FabricSemanticVersion.toFabric(org.quiltmc.loader.api.Version.Semantic.of(components, "", null));
} catch (VersionFormatException e) {
throw new IllegalStateException(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/quiltmc/loader/api/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ static Semantic of(int[] components, @Nullable String preRelease, @Nullable Stri
StringBuilder raw = new StringBuilder();
raw.append(Arrays.stream(components).mapToObj(Integer::toString).collect(Collectors.joining("."))); // 1.0.0

if (preRelease != null && !preRelease.isEmpty()) {
if (preRelease != null) {
raw.append('-').append(preRelease);
}

if (buildMetadata != null && !buildMetadata.isEmpty()) {
if (buildMetadata != null) {
raw.append('+').append(buildMetadata);
}
// HACK: re-building raw makes sure that everything is verified to be valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static VersionPredicate parse(String predicate) throws VersionParsingExce
}

try {
version = Quilt2FabricVersion.toFabric(org.quiltmc.loader.api.Version.Semantic.of(newComponents, "", semVer.getBuildKey().orElse("")));
version = Quilt2FabricVersion.toFabric(org.quiltmc.loader.api.Version.Semantic.of(newComponents, "", semVer.getBuildKey().orElse(null)));
} catch (VersionFormatException e) {
throw new IllegalStateException("Failed to reconstruct a version from " + version, e);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/net/fabricmc/test/VersionPredicateTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.fabricmc.test;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
import net.fabricmc.loader.api.metadata.version.VersionPredicate;

public class VersionPredicateTests {
@Test
public void testPredicates() throws VersionParsingException {
VersionPredicate predicate = VersionPredicate.parse("2.x.x");
Version version = Version.parse("2.0.0-beta3");
Assertions.assertTrue(predicate.test(version), predicate + " does not allow " + version);
}
}

0 comments on commit a4118a0

Please sign in to comment.