Skip to content

Commit

Permalink
Fixed version number parsing to properly detect numerical qualifiers.
Browse files Browse the repository at this point in the history
Fixes #30
Fixes #28
  • Loading branch information
gbevin committed May 1, 2024
1 parent 7083042 commit 917d6bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/rife/bld/dependencies/VersionNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public record VersionNumber(Integer major, Integer minor, Integer revision, Stri
*/
public static final VersionNumber UNKNOWN = new VersionNumber(0, 0, 0, "");

private static final Pattern VERSION_PATTERN = Pattern.compile("^(?<major>\\d+)(?:\\.(?<minor>\\d+)(?:\\.(?<revision>\\d+))?)?(?:(?<separator>[.\\-])(?<qualifier>.*[^.\\-]))??$");
private static final Pattern VERSION_PATTERN = Pattern.compile("^(?<major>0|[1-9]\\d*)(?:\\.(?<minor>0|[1-9]\\d*)(?:\\.(?<revision>0|[1-9]\\d*))?)?(?:(?<separator>[.\\-])(?<qualifier>.*[^.\\-]))??$");

/**
* Parses a version number from a string representation.
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/rife/bld/dependencies/TestVersionNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ void testParsing() {

assertEquals(VersionNumber.parse("1.2.3_4"), new VersionNumber(1, 2, 0, "3_4"));
assertEquals(VersionNumber.parse("1.54b"), new VersionNumber(1, 0, 0, "54b"));

assertEquals(VersionNumber.parse("2024-02"), new VersionNumber(2024, null, null, "02"));
assertEquals(VersionNumber.parse("2.0-05"), new VersionNumber(2, 0, null, "05"));
assertEquals(VersionNumber.parse("2024.02"), new VersionNumber(2024, null, null, "02", "."));
assertEquals(VersionNumber.parse("2.0.05"), new VersionNumber(2, 0, null, "05", "."));
}

@Test
Expand Down

0 comments on commit 917d6bb

Please sign in to comment.