Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ private Version[] parseVersionRange(String versionRange) {
if (versionRange.trim().equals("all")) {
return new Version[]{VersionUtils.getFirstVersion(), Version.CURRENT};
}
String[] skipVersions = versionRange.split("-");
if (skipVersions.length > 2) {
String[] skipVersions = versionRange.split("-(?=\\d+|\\s+|$)", -1);
if (skipVersions.length != 2) {
throw new IllegalArgumentException("version range malformed: " + versionRange);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
import org.elasticsearch.test.VersionUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
Expand All @@ -43,6 +45,38 @@ public void testSkip() {
assertTrue(section.skip(Version.CURRENT));
}

public void testParseVersionRange() throws Exception {
List<String> features = Collections.emptyList();
Arrays.asList("5.0.0 - 5.1.1", "5.0.0-5.1.1", "5.0.0- 5.1.1", "5.0.0 -5.1.1").forEach(
vr -> verifyVersionRange(vr, features, Version.V_5_0_0, Version.V_5_1_1));
Arrays.asList("5.0.0 - ", "5.0.0- ", "5.0.0 -", "5.0.0-").forEach(
vr -> verifyVersionRange(vr, features, Version.V_5_0_0, Version.CURRENT));
Arrays.asList(" - 5.0.0", " -5.0.0", "-5.0.0", "- 5.0.0").forEach(
vr -> verifyVersionRange(vr, features, VersionUtils.getFirstVersion(), Version.V_5_0_0));
Arrays.asList("5.0.0 - 6.0.0-rc1", "5.0.0 -6.0.0-rc1", "5.0.0- 6.0.0-rc1", "5.0.0-6.0.0-rc1").forEach(
vr -> verifyVersionRange(vr, features, Version.V_5_0_0, Version.V_6_0_0_rc1));
Arrays.asList("6.0.0-rc1 - 5.0.0", "6.0.0-rc1- 5.0.0", "6.0.0-rc1 -5.0.0", "6.0.0-rc1-5.0.0").forEach(
vr -> verifyVersionRange(vr, features, Version.V_6_0_0_rc1, Version.V_5_0_0));
Arrays.asList("5.0.0 - 6.0.0-beta1", "5.0.0 -6.0.0-beta1", "5.0.0- 6.0.0-beta1", "5.0.0-6.0.0-beta1").forEach(
vr -> verifyVersionRange(vr, features, Version.V_5_0_0, Version.V_6_0_0_beta1));
Arrays.asList("6.0.0-beta1 - 5.0.0", "6.0.0-beta1- 5.0.0", "6.0.0-beta1 -5.0.0", "6.0.0-beta1-5.0.0").forEach(
vr -> verifyVersionRange(vr, features, Version.V_6_0_0_beta1, Version.V_5_0_0));
Arrays.asList("5.0.0 - 6.0.0-alpha1", "5.0.0 -6.0.0-alpha1", "5.0.0- 6.0.0-alpha1", "5.0.0-6.0.0-alpha1").forEach(
vr -> verifyVersionRange(vr, features, Version.V_5_0_0, Version.V_6_0_0_alpha1));
Arrays.asList("6.0.0-alpha1 - 5.0.0", "6.0.0-alpha1- 5.0.0", "6.0.0-alpha1 -5.0.0", "6.0.0-alpha1-5.0.0").forEach(
vr -> verifyVersionRange(vr, features, Version.V_6_0_0_alpha1, Version.V_5_0_0));
Arrays.asList(" - 6.0.0-rc1", " -6.0.0-rc1", "- 6.0.0-rc1", "-6.0.0-rc1").forEach(
vr -> verifyVersionRange(vr, features, VersionUtils.getFirstVersion(), Version.V_6_0_0_rc1));
Arrays.asList("6.0.0-rc1 - ", "6.0.0-rc1- ", "6.0.0-rc1 -", "6.0.0-rc1-").forEach(
vr -> verifyVersionRange(vr, features, Version.V_6_0_0_rc1, Version.CURRENT));
}

private void verifyVersionRange(String versionRange, List<String> features, Version lowerVersion, Version upperVersion) {
SkipSection skipSection = new SkipSection(versionRange, features, "foo");
assertEquals(lowerVersion, skipSection.getLowerVersion());
assertEquals(upperVersion, skipSection.getUpperVersion());
}

public void testMessage() {
SkipSection section = new SkipSection("5.0.0 - 5.1.0",
Collections.singletonList("warnings"), "foobar");
Expand Down