Apply character-string escapes as bytes in URI, HINFO, X25, ISDN, NAPTR, and CAA - #1288
Open
gaoflow wants to merge 1 commit into
Open
Apply character-string escapes as bytes in URI, HINFO, X25, ISDN, NAPTR, and CAA#1288gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
…TR, and CAA URI.to_text() emitted the raw target with a bare decode(), crashing on wire-legal non-UTF-8 targets and corrupting backslashes and quotes on a text round trip. The parse side of URI, HINFO, X25, ISDN, NAPTR, and CAA also processed \ddd escapes as code points and then UTF-8 encoded them, so escapes greater than \127 became two octets instead of one (the double-encoding issue rthalley#321 fixed for TXT-like records). Add Tokenizer.get_bytes()/as_bytes() and use them for these fields, and escape the URI target on output, so that from_text(to_text()) is the identity for all octet values.
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.
URI records crash on printing when the wire target is not valid UTF-8, and silently corrupt backslashes and quotes on a text round trip, because
to_text()emits the raw target with a bare.decode()whilefrom_text()unescapes:Auditing the other free-form string fields: HINFO, X25, ISDN, NAPTR, and CAA escape correctly on output but still parse
\dddthrough the str-basedunescape(), so\255becomes the two octetsc3 bfinstead offf— the same double-encoding #321 fixed for TXT-like records withunescape_to_bytes(), which never reached these types. BIND round-trips\255in these fields as a single octet.This adds
Tokenizer.get_bytes()/as_bytes()(bytes counterpart ofget_string(), built onunescape_to_bytes(), with the length limit measured in bytes) and uses it for these fields, andURI.to_styled_text()now escapes the target with_escapifylike its siblings. Tests cover the URI crash and round-trip repros, plus\ddd-> octet andfrom_text(to_text())identity over all 256 octet values for all six types and TXT. Full pytest suite passes locally; ruff and pyright clean.