From 43e75f00a0ca0ba96e3f4f484531a7aa52028888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BIDON?= Date: Sat, 22 Aug 2026 14:40:40 +0200 Subject: [PATCH] fix(hostname): go1.27 idna valid label no longer tolerates trailing dot in hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We keep our existing behavior (follows https://url.spec.whatwg.org/#concept-host-parser) and trim any trailing dot before submitting the string to idna label check. Signed-off-by: Frédéric BIDON --- .golangci.yml | 1 + default.go | 3 ++- format.go | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 31480c7..ce7a6ae 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ linters: - gomodguard_v2 - godox - exhaustruct + - exhaustruct_v5 - nlreturn - nonamedreturns - noinlineerr diff --git a/default.go b/default.go index bcc57e6..9168d05 100644 --- a/default.go +++ b/default.go @@ -119,6 +119,7 @@ func IsHostname(str string) bool { } // IDNA check + str, _ = strings.CutSuffix(str, ".") // tolerates trailing ".", whereas IDNA ValidateLabel rule does not res, err := idnaHostChecker.ToASCII(strings.ToLower(str)) if err != nil || res == "" { return false @@ -1976,7 +1977,7 @@ func isISBN(str string, version int) bool { for i = range isbnVersion13 - 1 { checksum += factor[i%2] * int32(sanitized[i]-'0') } - return (int32(sanitized[isbnVersion13-1]-'0'))-((decimalBase-(checksum%decimalBase))%decimalBase) == 0 + return int32(sanitized[isbnVersion13-1]-'0')-((decimalBase-(checksum%decimalBase))%decimalBase) == 0 default: return isISBN(str, isbnVersion10) || isISBN(str, isbnVersion13) } diff --git a/format.go b/format.go index 09c3754..7ec7856 100644 --- a/format.go +++ b/format.go @@ -122,7 +122,7 @@ func (f *defaultFormats) Add(name string, strfmt Format, validator Validator) bo nme := f.normalizeName(name) tpe := reflect.TypeOf(strfmt) - if tpe.Kind() == reflect.Ptr { + if tpe.Kind() == reflect.Pointer { tpe = tpe.Elem() } @@ -176,7 +176,7 @@ func (f *defaultFormats) DelByFormat(strfmt Format) bool { defer f.Unlock() tpe := reflect.TypeOf(strfmt) - if tpe.Kind() == reflect.Ptr { + if tpe.Kind() == reflect.Pointer { tpe = tpe.Elem() } @@ -208,7 +208,7 @@ func (f *defaultFormats) ContainsFormat(strfmt Format) bool { f.Lock() defer f.Unlock() tpe := reflect.TypeOf(strfmt) - if tpe.Kind() == reflect.Ptr { + if tpe.Kind() == reflect.Pointer { tpe = tpe.Elem() }