template: dont truncate IPv6 zone identifiers in stripDomain

Signed-off-by: Jyotirmoy Roy <jyotirmoyroy649@gmail.com>
This commit is contained in:
Jyotirmoy Roy committed 2026-10-04 12:25:47 +05:30
1 parent 961c9ba409
commit 9494ffe7fb
2 files changed
+17 -2

No files matched your search

+2 -2
View File
@@ -22,6 +22,7 @@ import (
"maps"
"math"
"net"
"net/netip"
"net/url"
"sort"
"strings"
@@ -191,8 +192,7 @@ func NewTemplateExpander(
if err != nil {
host = hostPort
}
ip := net.ParseIP(host)
if ip != nil {
if _, err := netip.ParseAddr(host); err == nil {
return hostPort
}
host = strings.Split(host, ".")[0]
+15
View File
@@ -584,6 +584,21 @@ func TestTemplateExpansion(t *testing.T) {
text: "{{ \"[2001:0DB8::1]::12345\" | stripDomain }}",
output: "[2001:0DB8::1]::12345",
},
{
// IPv6 address with a zone identifier containing dots.
text: "{{ \"fe80::1%eth0.100\" | stripDomain }}",
output: "fe80::1%eth0.100",
},
{
// IPv6 address with a zone identifier containing dots and a port.
text: "{{ \"[fe80::1%eth0.100]:9090\" | stripDomain }}",
output: "[fe80::1%eth0.100]:9090",
},
{
// IPv4-mapped IPv6 address with a zone identifier containing dots.
text: "{{ \"::ffff:192.0.2.1%eth0.100\" | stripDomain }}",
output: "::ffff:192.0.2.1%eth0.100",
},
})
}