Skip to content

Commit c7573cf

Browse files
fix(registry): derive the add-source id from the full IPv6 host
deriveRegistryID dropped a port by cutting the host at the first ':'. For an IPv6 literal URL such as https://[2606:4700:4700::1111]/ that left only the first group, so the id became "2606" and a second registry in the same /16 was refused as a duplicate id. Pass u.Hostname(), which already strips the port and brackets, and drop the cut. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c82d515 commit c7573cf

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎internal/server/add_registry_source.go‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func buildRegistrySourceEntry(rawURL, protocol, id, name string) (config.Registr
226226
ErrUnsupportedRegistryProtocol, protocol, defaultRegistryProtocol)
227227
}
228228
if id == "" {
229-
id = deriveRegistryID(u.Host)
229+
id = deriveRegistryID(u.Hostname())
230230
}
231231
if name == "" {
232232
name = id
@@ -272,13 +272,11 @@ func validateNewRegistrySource(cfg *config.Config, entry config.RegistryEntry) e
272272
return nil
273273
}
274274

275-
// deriveRegistryID slugifies a host into a stable registry id, dropping a
276-
// leading "www." and a trailing port, and replacing non-alphanumerics with "-".
275+
// deriveRegistryID slugifies a hostname (no port, no IPv6 brackets) into a
276+
// stable registry id, dropping a leading "www." and replacing non-alphanumerics
277+
// with "-".
277278
func deriveRegistryID(host string) string {
278279
host = strings.ToLower(host)
279-
if h, _, ok := strings.Cut(host, ":"); ok {
280-
host = h
281-
}
282280
host = strings.TrimPrefix(host, "www.")
283281
var b strings.Builder
284282
for _, r := range host {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package server
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
// An IPv6 literal host contains colons. Cutting at the first ':' to drop a port
11+
// reduced every such host to its first group, so distinct registries collided
12+
// on the same derived id and the second one was refused as a duplicate.
13+
func TestBuildRegistrySourceEntry_IPv6HostID(t *testing.T) {
14+
cases := map[string]string{
15+
"https://[2606:4700:4700::1111]/": "2606-4700-4700--1111",
16+
"https://[2606:4700::64]:8443/": "2606-4700--64",
17+
"https://www.Registry.Example:8443/": "registry-example",
18+
"https://registry.acme.example/v0.1/": "registry-acme-example",
19+
}
20+
for raw, want := range cases {
21+
entry, err := buildRegistrySourceEntry(raw, "", "", "")
22+
require.NoError(t, err, raw)
23+
assert.Equal(t, want, entry.ID, raw)
24+
}
25+
}

0 commit comments

Comments
 (0)