Fix TXT round-trip for long and non-ASCII records#33
Open
bindreams wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #32.
TXT content was encoded with
fmt.Sprintf("%q", ...)and decoded by stripping the surrounding quotes. That pairing isn't symmetric and never chunked, so two things broke for TXT values over 255 bytes (DKIM keys, long SPF):GetRecordsreturnedTextwith Cloudflare's zone-file segment separators (" ") still embedded, because CF splits long values into multiple"..."strings and the old code only stripped the outermost quotes.DeleteRecordssilently matched nothing, because the lookup key was the unchunked%qstring while CF stored and returned the chunked form.Cloudflare's TXT
contentis RFC 1035 zone presentation: quoted character-strings,\DDDescapes, split at 255 octets. This swaps the wrap/unwrap helpers for a real encode/decode (txt.go) and matches TXT for deletion by decoded value instead of by raw presentation. Delete also now honors theRecordDeleter"empty value matches any value" rule for TXT (previously a silent no-op). TXT round-trips byte-for-byte at any length and with any byte content.While in
provider.goI fixed two unrelated pagination bugs inGetRecords:ResultInfowas dereferenced before its own nil check, and the page-count division could divide by zero ifper_pagecame back as 0. Both are guarded now. Happy to split these into a separate PR if you'd prefer.One thing I left alone on purpose: delete-matching compares name, type, and value but not TTL, which the
RecordDeletercontract also mentions. That predates this change and applies to every record type in the driver, so it felt out of scope here.Testing: codec unit tests (round-trip over every byte value, chunk boundaries, golden cases, error paths) plus live
libdnstestintegration tests for a DKIM-sized record, quotes and backslashes, raw bytes, SetRecords, and empty-value delete. The workflow now also runs the root module's unit tests.