feat: print TXT record values quoted, matching dig - #83
Merged
Conversation
dig wraps every TXT character-string in double quotes; tdig printed the value bare, so its output diverged from dig for every TXT lookup. Quote the value and escape `"` on top of the existing escaping. The quoting is deliberately kept out of escape/1, which is shared with the domain-name types (:ns, :ptr, :cname, :mx, :soa) that dig leaves unquoted; escape_character_string_byte/1 delegates to escape_byte/1 so the `\\` and `\DDD` rules stay in one place. Multi-character-string records still print as a single quoted value because tenbin_dns returns their concatenation and deliberately does not preserve boundaries (smkwlab/tenbin_dns#95), where dig prints `"abc" "def"`. No data is lost, and the difference is now documented in the README's dig comparison. Verified against `dig +noall +answer google.com TXT @8.8.8.8`: output matches for single-character-string records.
| end | ||
|
|
||
| defp escape_character_string_byte(?"), do: "\\\"" | ||
| defp escape_character_string_byte(byte), do: escape_byte(byte) |
Contributor
There was a problem hiding this comment.
✨ [POSITIVE] 実装・コメント・委譲設計とも良好です。escape_character_string_byte/1が"以外をescape_byte/1に委譲することで、\→\\や非印字バイト→\DDDのルールが1箇所に集約され、重複実装を回避できている点は保守性の観点で優れています。ドメイン名の非引用を守るためにTXT専用経路に閉じている判断も適切です。
toshi0806
added a commit
that referenced
this pull request
Aug 11, 2026
Minor rather than patch: this release changes tdig's output, so anyone parsing it is affected. - TXT values are now wrapped in double quotes, matching dig (#83) - Section records print in wire order; they were reversed before (via tenbin_dns 0.8.0, #80) - Long TXT values print in full; only the first character-string used to be read (via tenbin_dns 0.8.0, #80) - dig-style argument order is accepted and unknown types are rejected (#78) The release workflow refuses to publish when mix.exs and the pushed tag disagree, so this has to land before tagging 0.5.0.
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.
概要
TXT レコードの値を
digと同じく引用符付きで出力するようにします。Resolves #82
実装
rdata_to_string(rdata, :txt)を新設のquote_character_string/1経由に変更しました。escape/1自体は変更していません。 この関数は:ns/:ptr/:cname/:mx/:soaのドメイン名でも共用されており、digはドメイン名を引用しないためです。引用符の付与と"のエスケープは TXT 専用の経路に閉じています。escape_character_string_byte/1は"以外を既存のescape_byte/1に委譲するので、\→\\と非印字バイト →\DDDのルールは 1 箇所に保たれ、重複実装がありません。テスト(TDD)
実装前に red を確認してから着手しました。既存の 2 件は引用符なしを期待していたため更新しています。
formats TXT records— 引用符付きの期待値に更新(既存テストの更新)escapes double quotes inside TXT records—a"b→"a\"b"escapes backslashes inside TXT records—a\b→"a\\b"escapes non-printable bytes inside TXT records— ESC を含む値が"\027[31m"になるrenders an empty TXT record as empty quotes—""leaves domain names unquoted— 回帰防止。TXT の引用が:ns/:cname/:mxに漏れていないことを確認escapes untrusted TXT and name bytes— 引用符付きの期待値に更新(ESC エスケープの検証意図は維持)スコープ外: 複数 character-string の個別引用
digは複数 character-string を"abc" "def"と個別に引用しますが、本 PR では連結して"abcdef"と表示します。tenbin_dns の
decode(rdata, :txt, _, _)が全 character-string を連結した単一バイナリを返し、境界情報を保持しないためです。これは smkwlab/tenbin_dns#95 で 3 案を比較したうえで選択された設計で、境界非保持は受容されたトレードオフとして記録されています(RFC 7208 §3.3 のとおり SPF 等では連結値が論理値)。tenbin_dns 側での再検討も提起しましたが、この判断を覆すには至らないと結論しています。値そのものは完全に表示されるため情報の欠落はありません。 README の dig 比較表に既知の差異として記載し、コード側にもコメントで経緯を残しました。
動作確認
実機で
digと比較し、単一 character-string のケースで出力が完全に一致することを確認しました。品質チェック:
mix test: 60 passedmix credo --strict: no issuesmix format --check-formatted: OKmix compile --force --warnings-as-errors: 警告なし補足
引用符が付いていなかったのは tenbin_dns 0.8.0 以前からの挙動で、今回の依存更新による退行ではありません。なお 0.7.1 では TXT の最初の character-string しか取得できず(残りは破棄)、255 バイト超の TXT は値が途中で切れて表示されていました。0.8.0 で全体が表示されるようになっています。