Skip to content

Commit

Permalink
Fix version parser used by gradle (elastic#51773)
Browse files Browse the repository at this point in the history
Due to of a typo in the version regex pattern only the last digit of a major
version number is taken into consideration. So docker's version 17.0.1 is parsed
as 7.0.1.
  • Loading branch information
imotov committed Feb 3, 2020
1 parent 8fa4a40 commit cff3fdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public enum Mode {
RELAXED
}

private static final Pattern pattern = Pattern.compile("(\\d)+\\.(\\d+)\\.(\\d+)(-alpha\\d+|-beta\\d+|-rc\\d+)?(-SNAPSHOT)?");
private static final Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(-alpha\\d+|-beta\\d+|-rc\\d+)?(-SNAPSHOT)?");

private static final Pattern relaxedPattern = Pattern.compile("(\\d)+\\.(\\d+)\\.(\\d+)(-[a-zA-Z0-9_]+)*?");
private static final Pattern relaxedPattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(-[a-zA-Z0-9_]+)*?");

public Version(int major, int minor, int revision) {
Objects.requireNonNull(major, "major version can't be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void testVersionParsing() {
assertVersionEquals("5.1.2-rc3", 5, 1, 2);
assertVersionEquals("6.1.2-SNAPSHOT", 6, 1, 2);
assertVersionEquals("6.1.2-beta1-SNAPSHOT", 6, 1, 2);
assertVersionEquals("17.03.11", 17, 3, 11);
}

public void testRelaxedVersionParsing() {
Expand All @@ -46,6 +47,7 @@ public void testRelaxedVersionParsing() {
assertVersionEquals("6.1.2-beta1-SNAPSHOT", 6, 1, 2, Version.Mode.RELAXED);
assertVersionEquals("6.1.2-foo", 6, 1, 2, Version.Mode.RELAXED);
assertVersionEquals("6.1.2-foo-bar", 6, 1, 2, Version.Mode.RELAXED);
assertVersionEquals("16.01.22", 16, 1, 22, Version.Mode.RELAXED);
}

public void testCompareWithStringVersions() {
Expand Down Expand Up @@ -91,6 +93,7 @@ public void testToString() {

public void testCompareVersions() {
assertEquals(0, new Version(7, 0, 0).compareTo(new Version(7, 0, 0)));
assertOrder(Version.fromString("19.0.1"), Version.fromString("20.0.3"));
}

public void testExceptionEmpty() {
Expand Down

0 comments on commit cff3fdb

Please sign in to comment.