diff --git a/CHANGELOG.md b/CHANGELOG.md index 3964f9d..0e18b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ All notable changes to the Docker Language Server will be documented in this fil - Compose - textDocument/completion - prevent wildcard object attribute suggestions if the text cursor is not at the right indentation for attributes to be inserted ([#342](https://github.com/docker/docker-language-server/issues/342)) + - textDocument/documentLink + - fix bounds index error if a quoted string just has a registry and the colon character at the end ([#351](https://github.com/docker/docker-language-server/issues/351)) ## [0.13.0] - 2025-07-09 diff --git a/internal/compose/documentLink.go b/internal/compose/documentLink.go index eaed46c..f1427fc 100644 --- a/internal/compose/documentLink.go +++ b/internal/compose/documentLink.go @@ -231,33 +231,33 @@ func DocumentLink(ctx context.Context, documentURI protocol.URI, doc document.Co func extractImageLink(nodeValue string) (string, string) { if strings.HasPrefix(nodeValue, "ghcr.io") { + if len(nodeValue) <= 8 { + return "", "" + } idx := strings.LastIndex(nodeValue, ":") if idx == -1 { - if len(nodeValue) <= 8 { - return "", "" - } return nodeValue, fmt.Sprintf("https://%v", nodeValue) } return nodeValue[0:idx], fmt.Sprintf("https://%v", nodeValue[0:idx]) } if strings.HasPrefix(nodeValue, "mcr.microsoft.com") { + if len(nodeValue) <= 18 { + return "", "" + } idx := strings.LastIndex(nodeValue, ":") if idx == -1 { - if len(nodeValue) <= 18 { - return "", "" - } return nodeValue, fmt.Sprintf("https://mcr.microsoft.com/artifact/mar/%v", nodeValue[18:]) } return nodeValue[0:idx], fmt.Sprintf("https://mcr.microsoft.com/artifact/mar/%v", nodeValue[18:idx]) } if strings.HasPrefix(nodeValue, "quay.io") { + if len(nodeValue) <= 8 { + return "", "" + } idx := strings.LastIndex(nodeValue, ":") if idx == -1 { - if len(nodeValue) <= 8 { - return "", "" - } return nodeValue, fmt.Sprintf("https://quay.io/repository/%v", nodeValue[8:]) } return nodeValue[0:idx], fmt.Sprintf("https://quay.io/repository/%v", nodeValue[8:idx]) diff --git a/internal/compose/documentLink_test.go b/internal/compose/documentLink_test.go index eeec5f6..ad62b96 100644 --- a/internal/compose/documentLink_test.go +++ b/internal/compose/documentLink_test.go @@ -501,6 +501,14 @@ services: image: ghcr.io:`, links: nil, }, + { + name: "image: \"ghcr.io:\"", + content: ` +services: + test: + image: "ghcr.io:"`, + links: []protocol.DocumentLink{}, + }, { name: "image: mcr.microsoft.com/powershell", content: ` @@ -593,6 +601,14 @@ services: image: mcr.microsoft.com:`, links: nil, }, + { + name: "image: \"mcr.microsoft.com:\"", + content: ` +services: + test: + image: "mcr.microsoft.com:"`, + links: []protocol.DocumentLink{}, + }, { name: "image: quay.io/prometheus/node-exporter", content: ` @@ -651,6 +667,14 @@ services: image: quay.io:`, links: nil, }, + { + name: "image: \"quay.io:\"", + content: ` +services: + test: + image: "quay.io:"`, + links: []protocol.DocumentLink{}, + }, { name: "anchors and aliases to nothing", content: `