diff --git a/CHANGELOG.md b/CHANGELOG.md index f23fc376..4bd11cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ released by then. ### Fixed +- Domain name letter case mismatches in DNS rewrites ([#3351]). - Conflicts between IPv4 and IPv6 DNS rewrites ([#3343]). - Letter case mismatches in `CNAME` filtering ([#3335]). - Occasional breakages on network errors with DNS-over-HTTP upstreams ([#3217]). @@ -105,6 +106,7 @@ released by then. [#3257]: https://github.com/AdguardTeam/AdGuardHome/issues/3257 [#3335]: https://github.com/AdguardTeam/AdGuardHome/issues/3335 [#3343]: https://github.com/AdguardTeam/AdGuardHome/issues/3343 +[#3351]: https://github.com/AdguardTeam/AdGuardHome/issues/3351 diff --git a/internal/filtering/rewrites.go b/internal/filtering/rewrites.go index 12dc5f21..80786d76 100644 --- a/internal/filtering/rewrites.go +++ b/internal/filtering/rewrites.go @@ -80,6 +80,11 @@ func (a rewritesSorted) Less(i, j int) bool { // prepare prepares the a new or decoded entry. func (r *RewriteEntry) prepare() { + // TODO(a.garipov): Write a case-agnostic version of strings.HasSuffix + // and use it in matchDomainWildcard instead of using strings.ToLower + // everywhere. + r.Domain = strings.ToLower(r.Domain) + switch r.Answer { case "AAAA": r.IP = nil diff --git a/internal/filtering/rewrites_test.go b/internal/filtering/rewrites_test.go index 462e059e..d0591988 100644 --- a/internal/filtering/rewrites_test.go +++ b/internal/filtering/rewrites_test.go @@ -63,6 +63,9 @@ func TestRewrites(t *testing.T) { }, { Domain: "*.hostboth.com", Answer: "1234::5678", + }, { + Domain: "BIGHOST.COM", + Answer: "1.2.3.7", }} d.prepareRewrites() @@ -126,6 +129,12 @@ func TestRewrites(t *testing.T) { wantCName: "", wantVals: []net.IP{net.ParseIP("1234::5678")}, dtyp: dns.TypeAAAA, + }, { + name: "issue3351", + host: "bighost.com", + wantCName: "", + wantVals: []net.IP{{1, 2, 3, 7}}, + dtyp: dns.TypeA, }} for _, tc := range testCases { @@ -139,7 +148,8 @@ func TestRewrites(t *testing.T) { return } - require.Equal(t, Rewritten, r.Reason) + require.Equalf(t, Rewritten, r.Reason, "got %s", r.Reason) + if tc.wantCName != "" { assert.Equal(t, tc.wantCName, r.CanonName) } @@ -319,7 +329,7 @@ func TestRewritesExceptionIP(t *testing.T) { return } - assert.Equal(t, Rewritten, r.Reason) + assert.Equalf(t, Rewritten, r.Reason, "got %s", r.Reason) require.Len(t, r.IPList, len(tc.want))