From 507dc4e0addbd43dde4e9501962de9264e65069e Mon Sep 17 00:00:00 2001 From: Thomas Limoncelli Date: Fri, 21 Nov 2025 11:50:30 -0500 Subject: [PATCH] fixup! --- commands/commands.go | 16 +++++++++++++++- commands/ppreviewPush.go | 1 + pkg/normalize/validate.go | 21 ++++++++++++--------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index fbf1265ac..31fe4b490 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -14,6 +14,7 @@ import ( "github.com/StackExchange/dnscontrol/v4/pkg/version" "github.com/fatih/color" "github.com/urfave/cli/v2" + "golang.org/x/net/idna" ) // categories of commands @@ -308,7 +309,7 @@ func (args *FilterArgs) flags() []cli.Flag { // domain is in the list, accounting for wildcards and tags. func domainInList(domain string, list []string) bool { for _, item := range list { - if item == domain { + if downgradeIDNA(item) == downgradeIDNA(domain) { return true } if strings.HasPrefix(item, "*") && strings.HasSuffix(domain, item[1:]) { @@ -316,6 +317,11 @@ func domainInList(domain string, list []string) bool { } filterDom, filterTag, isFilterTagged := strings.Cut(item, "!") splitDom, domainTag, isDomainTagged := strings.Cut(domain, "!") + + splitDom = downgradeIDNA(splitDom) + filterDom = downgradeIDNA(filterDom) + //fmt.Printf("###DEBUG: does %q == %q? %v\n", splitDom, filterDom, splitDom == filterDom) + if splitDom == filterDom { if isDomainTagged { if filterTag == "*" { @@ -339,3 +345,11 @@ func domainInList(domain string, list []string) bool { } return false } + +func downgradeIDNA(s string) string { + u, err := idna.ToASCII(s) + if err != nil { + return s // There was a problem. Abort and return the original. + } + return u +} diff --git a/commands/ppreviewPush.go b/commands/ppreviewPush.go index 5e29d1a3d..2e2f6a853 100644 --- a/commands/ppreviewPush.go +++ b/commands/ppreviewPush.go @@ -420,6 +420,7 @@ func prun(args PPreviewArgs, push bool, interactive bool, out printer.CLI, repor // filter. The filter string is a comma-separated list of domain names. If the // filter string is empty or "all", all domains are returned. func whichZonesToProcess(domains []*models.DomainConfig, filter string) []*models.DomainConfig { + fmt.Printf("###DEBUG: whichZonesToProcess filter=%q\n", filter) if filter == "" || filter == "all" { return domains } diff --git a/pkg/normalize/validate.go b/pkg/normalize/validate.go index 1c1903bbe..3587481cf 100644 --- a/pkg/normalize/validate.go +++ b/pkg/normalize/validate.go @@ -354,21 +354,24 @@ type Warning struct { // ValidateAndNormalizeConfig performs and normalization and/or validation of the IR. func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) { + + // This is a horrible hack. We need to redo IDN processing someday. + // For now, we just convert everything to punycode at the earliest point, which is here. + for _, domain := range config.Domains { + // Convert domain name to punycode. + var err error + domain.Name, err = idna.ToASCII(domain.Name) + if err != nil { + return []error{fmt.Errorf("Can not convert domain %q to IDN: %w", domain.Name, err)} + } + } + err := processSplitHorizonDomains(config) if err != nil { return []error{err} } for _, domain := range config.Domains { - - // Convert domain name to punycode. - // In the future, we should do something more sophisticated like having a .Name/.NameUnicode/.NameIDN so that users can see. - var err error - domain.Name, err = idna.ToASCII(domain.Name) - if err != nil { - return []error{fmt.Errorf("Can not convert domain %q to IDN: %w", domain.Name, err)} - } - pTypes := []string{} for _, provider := range domain.DNSProviderInstances { pType := provider.ProviderType