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

Commit e8f7a1a

Browse files
fix(docker): fix the issue of fetching docker images (#6372)
* test(docker): add a test to demonstrate the issue of fetching docker images due to `java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1` * fix(docker): fix the issue of fetching docker images due to `java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1`
1 parent f0abfea commit e8f7a1a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

clouddriver-docker/src/main/groovy/com/netflix/spinnaker/clouddriver/docker/registry/api/v2/client/DockerRegistryClient.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ class DockerRegistryClient {
499499
}
500500
if (queryParamsString) {
501501
queryParams = queryParamsString.split("&").collectEntries { param ->
502-
def (key, value) = param.split("=")
502+
// ensures two strings are returned even when a query parameter has no value(returns empty string).
503+
def (key, value) = param.split("=", 2)
503504
[key, value]
504505
}
505506
}

clouddriver-docker/src/test/java/com/netflix/spinnaker/clouddriver/docker/registry/api/v2/client/DockerRegistryClientTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,34 @@ public void testTagsResponse_With_AdditionalFields() throws JsonProcessingExcept
248248
String[] tags = (String[]) tagsResponse.get("tags");
249249
assertIterableEquals(Arrays.asList(tags), dockerRegistryTags.getTags());
250250
}
251+
252+
@Test
253+
public void getTags_WithNextLink_Having_No_QueryParam_Value() {
254+
wmDockerRegistry.stubFor(
255+
WireMock.get(urlMatching("/v2/library/nginx/tags/list\\?n=5"))
256+
.willReturn(
257+
aResponse()
258+
.withStatus(HttpStatus.OK.value())
259+
.withHeader(
260+
"link",
261+
"</v2/library/nginx/tags/list?last=1-alpine-slim&n=5&orderby=>; rel=\"next\"")
262+
.withBody(tagsResponseString)));
263+
wmDockerRegistry.stubFor(
264+
WireMock.get(urlMatching("/v2/library/nginx/tags/list\\?last=1-alpine-slim&n=5&orderby="))
265+
.willReturn(
266+
aResponse()
267+
.withStatus(HttpStatus.OK.value())
268+
.withHeader(
269+
"link",
270+
// to test the logic when `?` is not present in the link header
271+
"</v2/library/nginx/tags/list1>; rel=\"next\"")
272+
.withBody(tagsSecondResponseString)));
273+
wmDockerRegistry.stubFor(
274+
WireMock.get(urlMatching("/v2/library/nginx/tags/list1\\?n=5"))
275+
.willReturn(
276+
aResponse().withStatus(HttpStatus.OK.value()).withBody(tagsThirdResponseString)));
277+
278+
DockerRegistryTags dockerRegistryTags = dockerRegistryClient.getTags("library/nginx");
279+
assertEquals(15, dockerRegistryTags.getTags().size());
280+
}
251281
}

0 commit comments

Comments
 (0)