mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-07 01:56:57 +02:00
Merge pull request #736 from ottoyiu/fix-domainfilter
Fix domain-filter matching logic to not match similar domain names
This commit is contained in:
commit
2668b9f4ba
@ -46,8 +46,17 @@ func (df DomainFilter) Match(domain string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, filter := range df.filters {
|
for _, filter := range df.filters {
|
||||||
|
strippedDomain := strings.TrimSuffix(domain, ".")
|
||||||
|
|
||||||
if strings.HasSuffix(strings.TrimSuffix(domain, "."), filter) {
|
if filter == "" {
|
||||||
|
return true
|
||||||
|
} else if strings.HasPrefix(filter, ".") && strings.HasSuffix(strippedDomain, filter) {
|
||||||
|
return true
|
||||||
|
} else if strings.Count(strippedDomain, ".") == strings.Count(filter, ".") {
|
||||||
|
if strippedDomain == filter {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else if strings.HasSuffix(strippedDomain, "."+filter) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,36 @@ var domainFilterTests = []domainFilterTest{
|
|||||||
[]string{"foo.bar.sub.example.org"},
|
[]string{"foo.bar.sub.example.org"},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
[]string{"example.org"},
|
||||||
|
[]string{"anexample.org", "test.anexample.org"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[]string{".example.org"},
|
||||||
|
[]string{"anexample.org", "test.anexample.org"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[]string{".example.org"},
|
||||||
|
[]string{"example.org"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[]string{".example.org"},
|
||||||
|
[]string{"test.example.org"},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[]string{"anexample.org"},
|
||||||
|
[]string{"example.org", "test.example.org"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[]string{".org"},
|
||||||
|
[]string{"example.org", "test.example.org", "foo.test.example.org"},
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDomainFilterMatch(t *testing.T) {
|
func TestDomainFilterMatch(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user