fix: handle IPv6 host URLs in parseGitLabHostURL#6
Merged
Conversation
parseGitLabHostURL split host:port with strings.Split + a len==2 check, so an IPv6 host (many colons) skipped the port split and kept its brackets and port, e.g. host = "[2335::aa1:1415]:32336". Rendered into the GitLab test-data template this produced `host: [2335::aa1:1415]:32336`, whose leading "[" makes YAML parse it as a flow sequence, failing the e2e prepare-gitlab-data step on IPv6 environments with "yaml: line 3: did not find expected key". IPv4 splits into two parts so it worked; the bug was IPv6-only. Parse with net/url instead (matching the sibling parseGitLabSSHEndpoint): url.Hostname() returns the bare host so the rendered host: scalar is valid YAML, and the endpoint is rebuilt with net.JoinHostPort so IPv6 stays bracketed. Preserves the default-port-omitted endpoint contract, subpath GitLab installs, and non-corrupting fallback for no-scheme/malformed input. Add internal/cli/cmd_test.go: table-driven TestParseGitLabHostURL (IPv6/ IPv4/hostname, ports, subpaths, no-scheme bare IPv6, malformed fallback) and TestGeneratedHostValueIsValidYAML as a regression guard for the original YAML failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On IPv6 GitLab environments,
make prepare-gitlab-datafails deterministically and the whole e2e suite space-runs (zero tests, empty Allure report). The failure surfaces in the downstream YAML merge:Root cause
parseGitLabHostURLparsedhost:portwith a naive split:An IPv6 host has many colons, so
len(parts) != 2, the port split is skipped, andhostkeeps its brackets and port:[2335::aa1:1415]:32336. That value is rendered intousers-generated.yamlas:Because the
host:value starts with[, YAML treats it as a flow sequence and the load fails withdid not find expected key. IPv4 (10.161.11.29:32739) splits into exactly two parts, so it works — the bug is IPv6-only. The siblingparseGitLabSSHEndpointin the same file already parses correctly vianet/url; this function simply never got the same treatment.Fix
Rewrite
parseGitLabHostURLto parse withnet/url:url.Hostname()returns the bare host (IPv6 brackets stripped), so the renderedhost:scalar is valid YAML (2335::aa1:1415).net.JoinHostPort/ explicit bracketing re-adds brackets when rebuilding theendpoint, so it stays a valid URL (http://[2335::aa1:1415]:32336).https://gitlab.example.com/gitlab) keeps its path.Tests
New
internal/cli/cmd_test.go:TestParseGitLabHostURL— table-driven, 15 cases: IPv6 with/without port (http+https), IPv4 with/without port, hostname, subpath (hostname and IPv6), no-scheme bare IPv6 (with and without subpath), trailing slash, malformed-URL fallback, whitespace trimming.TestGeneratedHostValueIsValidYAML— regression guard tying the fix to the original failure: renders thetoolchains/gitlab/{endpoint,host}snippet for the IPv6 case and asserts it round-trips through YAML.go build ./...,go test ./..., andgofmt -lall clean.