Repository navigation
[Go] Escape and bound char fields in JSON printer output - #1189
Open
slachiewicz wants to merge 1 commit into
Open
slachiewicz wants to merge 1 commit into
slachiewicz wants to merge 1 commit into
Conversation
A single char field is limited to its own byte, and every char byte and var-data byte is escaped as JSON, with control characters as short escapes or \u00XX. The array layout (one string per element) is unchanged.
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.
JsonPrinterwrote a single char field as the whole remaining buffer, raw and unquoted, and wrote char array elements and var-data bytes without proper escaping (control characters came out as a backslash plus the raw byte). A frame could therefore break the JSON structure of the output. A single char now renders exactly its own byte, and every char byte and var-data byte goes through one escape routine that emits\",\\, the short escapes and\u00XX.Both reported findings are fixed here because they share the escape routine: the single-char fix would otherwise depend on it. The existing array layout (one string per element, for example
["a", "b"]) is kept, since changing it would change documented output.Part of #969.
Verified:
TestJsonCharFieldsAreEscapedandTestJsonPlainCharFieldsAreUnchangedfail on master (invalid JSON: invalid character ... after object key:value pair, even for a plainSsingle char, which printedSabcdfl note) and pass here;gocodemakepasses.