Skip to content

[Go] Escape and bound char fields in JSON printer output - #1189

Open
slachiewicz wants to merge 1 commit into
aeron-io:masterfrom
slachiewicz:go-json-printer-escaping
Open

slachiewicz wants to merge 1 commit into
aeron-io:masterfrom
slachiewicz:go-json-printer-escaping

Conversation

@slachiewicz

Copy link
Copy Markdown
Contributor

JsonPrinter wrote 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: TestJsonCharFieldsAreEscaped and TestJsonPlainCharFieldsAreUnchanged fail on master (invalid JSON: invalid character ... after object key:value pair, even for a plain S single char, which printed Sabcdfl note) and pass here; gocode make passes.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant