From dde1cd663ee364a9d4ab2747940e2e408501ad2a Mon Sep 17 00:00:00 2001 From: rvasikarla Date: Sun, 5 Apr 2026 18:17:14 -0500 Subject: [PATCH] fix: display long TXT records as one string in preview The preview/diff output previously showed long TXT records as 255-octet chunks (e.g., "255chars" "255chars" "rest"), which is confusing to users and violates Opinion #8 (TXT records are one long string). Add EncodeSingle() to txtutil that quotes the TXT value without splitting into 255-octet chunks, and use it in ToComparableNoTTL() so that the diff preview shows TXT records as a single string. The zone file output (prettyzone) continues to use EncodeQuoted() with chunking, as that format is required for zone file syntax. Fixes #2834 --- models/record.go | 2 +- pkg/txtutil/txtcode.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/models/record.go b/models/record.go index 4635d6eb8e..ff60bc9917 100644 --- a/models/record.go +++ b/models/record.go @@ -344,7 +344,7 @@ func (rc *RecordConfig) ToComparableNoTTL() string { // SoaSerial is not included because it isn't used in comparisons. case "TXT": // fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL raw txts=%s q=%q\n", rc.target, rc.target) - r := txtutil.EncodeQuoted(rc.target) + r := txtutil.EncodeSingle(rc.target) // fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL cmp txts=%s q=%q\n", r, r) return r case "LUA": diff --git a/pkg/txtutil/txtcode.go b/pkg/txtutil/txtcode.go index b5b1afb3b6..b412b6b4c5 100644 --- a/pkg/txtutil/txtcode.go +++ b/pkg/txtutil/txtcode.go @@ -36,6 +36,13 @@ func EncodeQuoted(t string) string { return txtEncode(ToChunks(t)) } +// EncodeSingle encodes a string as a single quoted value without splitting +// into 255-octet chunks. This is intended for user-facing display (e.g., diff +// preview) where the chunked representation is confusing. +func EncodeSingle(t string) string { + return txtEncode([]string{t}) +} + // State denotes the parser state. type State int