fix: escape DEL, C1 controls, and invalid UTF-8 in log output#32
Merged
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.
log_enc()escaped C0 controls, quotes, and backslashes, but passed bytes0x7F–0xFF through raw — in bare tokens as well as quoted values. DEL and
single-byte C1 controls (e.g. 0x9B CSI) could therefore reach the terminal
unescaped, and malformed byte sequences could corrupt log-line structure.
The encoder is now UTF-8 aware, in the spirit of Go's
log/slog:encodings, surrogates, and code points above U+10FFFF are rejected.
legitimate non-ASCII text is unaffected.
byte-wise as
\xNN.needs_quote()applies the same classification, so bare tokenscontaining such bytes are now quoted and escaped.
Test plan
log_enc()cases int/test_log.c(DEL, C1 raw and encoded,overlongs, surrogates, out-of-range, truncated sequences, resync after a
bad lead byte, and pass-through of valid 2/3/4-byte UTF-8)