Repository navigation
Quote logfmt values that contain tabs or other whitespace - #847
Open
spicysharkco wants to merge 3 commits into
Open
spicysharkco wants to merge 3 commits into
spicysharkco wants to merge 3 commits into
Conversation
LogfmtRenderer only quoted values containing a space, "=" or a double quote, so a tab or carriage return split the value when the line was parsed back. Quote any value with a character up to a space, except newline, which stays escaped.
Merging this PR will not alter performance
|
go-logfmt rejects a quoted value that holds a raw control character next to an escape, so a value such as "Foo\n\tat_bar" made the parser drop the rest of the record. Write tab, carriage return and the other characters below space as \t, \r and \u00XX, as go-logfmt's own encoder does for tab and carriage return.
This branch has not been deployed
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.
Summary
LogfmtRendererquotes a value only when it contains a space,=or". A tab or carriage return is written bare, so{"k": "a\tb", "after": "x"}renders ask=a<TAB>b after=x, and go-logfmt reads that back ask=a,b=""andafter=x.Values containing any character from NUL to space are now quoted, the same range the renderer already rejects in keys. Newline is left out of that check because it is escaped as
\n, as before.Inside the quotes, control characters are escaped as
\t,\ror\u00XXrather than written raw. go-logfmt rejects a quoted value that holds a raw control character together with an escape, so a stack trace line such as"Foo\n\tat_bar"would make it drop the rest of the record. go-logfmt's own encoder escapes tab and carriage return the same way. The new rows intest_escaping(a tab, a carriage return, a tab next to a newline, and\x01) fail without the change.Pull Request Checklist
mainbranch.api.py. (n/a, no new APIs)docs/api.rstby hand. (n/a)versionadded,versionchanged, ordeprecateddirectives. (n/a).rstand.mdfiles is written using semantic newlines.