From 9494ffe7fb42e48bfced76924a8a5ca1bfe618bd Mon Sep 17 00:00:00 2001 From: Jyotirmoy Roy Date: Sun, 4 Oct 2026 12:25:47 +0530 Subject: [PATCH] template: dont truncate IPv6 zone identifiers in stripDomain Signed-off-by: Jyotirmoy Roy --- template/template.go | 4 ++-- template/template_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/template/template.go b/template/template.go index 0ea7382ed3..7fdd96fc5f 100644 --- a/template/template.go +++ b/template/template.go @@ -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] diff --git a/template/template_test.go b/template/template_test.go index 073300a39b..7f06a6d55d 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -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", + }, }) }