Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.

Commit 03adbee

Browse files
committed
Fail with an explicit exception for invalid versions
1 parent 03a9813 commit 03adbee

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

engine/src/main/java/de/gesellix/docker/engine/DockerVersion.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public static DockerVersion parseDockerVersion(String version) {
1919

2020
final DockerVersion parsedVersion = new DockerVersion();
2121
Matcher matcher = versionPattern.matcher(version);
22-
matcher.matches();
22+
if (!matcher.matches()) {
23+
throw new IllegalArgumentException(String.format("Version does not match the expected version pattern: '%s'", version));
24+
}
2325
parsedVersion.setMajor(Integer.parseInt(matcher.group(1)));
2426
parsedVersion.setMinor(Integer.parseInt(matcher.group(2)));
2527
final String s = matcher.group(3);

engine/src/test/groovy/de/gesellix/docker/engine/DockerVersionSpec.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ import static de.gesellix.docker.engine.DockerVersion.parseDockerVersion
77

88
class DockerVersionSpec extends Specification {
99

10+
def "fails for invalid version"() {
11+
given:
12+
// this pattern appears in the wild for packages installed from
13+
// https://master.dockerproject.org/
14+
String versionString = "master-dockerproject-2022-03-26"
15+
16+
when:
17+
parseDockerVersion(versionString)
18+
19+
then:
20+
def e = thrown(IllegalArgumentException)
21+
e.message == "Version does not match the expected version pattern: '$versionString'"
22+
}
23+
1024
@Unroll
1125
def "parse version #versionString"() {
1226
expect:

0 commit comments

Comments
 (0)