From 063e4e54647cb93b2f5b2891afca9b98b589fdaf Mon Sep 17 00:00:00 2001 From: sjhddh Date: Tue, 21 Apr 2026 13:06:52 +0200 Subject: [PATCH 1/2] strmatcher: restore lenient Type.New(Domain) behavior The geodata refactor (#5814) added a ToDomain() validation call inside Type.New(Domain), which rejects any character outside the Letter-Digit- Hyphen subset. This is a silent breaking change: patterns that previously returned a matcher (that simply failed to match at runtime) now cause hard startup errors for any config containing an underscore in a domain rule (SRV-style names like _sip._tcp.example.com, internal service names, etc.). Type.New and Type.NewDomainPattern were introduced in the refactor as a lenient/strict API pair. Leaving ToDomain() inside Type.New(Domain) collapses that distinction and surprises existing users. Remove the validation from Type.New(Domain) so it matches pre-refactor behavior; NewDomainPattern remains strict for callers that want validation. Add a regression test covering underscore-containing patterns. Fixes #5986 --- common/geodata/strmatcher/matchers.go | 4 ---- common/geodata/strmatcher/matchers_test.go | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common/geodata/strmatcher/matchers.go b/common/geodata/strmatcher/matchers.go index fa28880461d0..7a2254585319 100644 --- a/common/geodata/strmatcher/matchers.go +++ b/common/geodata/strmatcher/matchers.go @@ -100,10 +100,6 @@ func (t Type) New(pattern string) (Matcher, error) { case Substr: return SubstrMatcher(pattern), nil case Domain: - pattern, err := ToDomain(pattern) - if err != nil { - return nil, err - } return DomainMatcher(pattern), nil case Regex: // 1. regex matching is case-sensitive regex, err := regexp.Compile(pattern) diff --git a/common/geodata/strmatcher/matchers_test.go b/common/geodata/strmatcher/matchers_test.go index 5f3f05b3bba3..8852848f2ed8 100644 --- a/common/geodata/strmatcher/matchers_test.go +++ b/common/geodata/strmatcher/matchers_test.go @@ -74,6 +74,23 @@ func TestMatcher(t *testing.T) { } } +func TestTypeNewDomainLenient(t *testing.T) { + // Type.New(Domain) is the general-purpose API and must not reject patterns + // that were accepted before the geodata refactor (including underscore, which + // is common in internal service DNS names and SRV records). Strict validation + // lives on Type.NewDomainPattern. + patterns := []string{ + "_sip._tcp.example.com", + "api_internal.local", + "example.com", + } + for _, p := range patterns { + if _, err := Domain.New(p); err != nil { + t.Errorf("Domain.New(%q) returned unexpected error: %v", p, err) + } + } +} + func TestToDomain(t *testing.T) { { // Test normal ASCII domain, which should not trigger new string data allocation input := "example.com" From d0ce6e955badba64712ebe2ea3f39fc45972345f Mon Sep 17 00:00:00 2001 From: Meow <197331664+Meo597@users.noreply.github.com> Date: Tue, 21 Apr 2026 20:57:32 +0800 Subject: [PATCH 2/2] Remove TestTypeNewDomainLenient function Removed TestTypeNewDomainLenient to simplify tests. --- common/geodata/strmatcher/matchers_test.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/common/geodata/strmatcher/matchers_test.go b/common/geodata/strmatcher/matchers_test.go index 8852848f2ed8..5f3f05b3bba3 100644 --- a/common/geodata/strmatcher/matchers_test.go +++ b/common/geodata/strmatcher/matchers_test.go @@ -74,23 +74,6 @@ func TestMatcher(t *testing.T) { } } -func TestTypeNewDomainLenient(t *testing.T) { - // Type.New(Domain) is the general-purpose API and must not reject patterns - // that were accepted before the geodata refactor (including underscore, which - // is common in internal service DNS names and SRV records). Strict validation - // lives on Type.NewDomainPattern. - patterns := []string{ - "_sip._tcp.example.com", - "api_internal.local", - "example.com", - } - for _, p := range patterns { - if _, err := Domain.New(p); err != nil { - t.Errorf("Domain.New(%q) returned unexpected error: %v", p, err) - } - } -} - func TestToDomain(t *testing.T) { { // Test normal ASCII domain, which should not trigger new string data allocation input := "example.com"