diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-10 16:09:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 16:09:52 +0100 |
| commit | fef00dda24b9832154a2e7b260fd61121c6e5561 (patch) | |
| tree | a1138fcafbcb0277ca878e6aa272b5a5e8828854 | |
| parent | 475791476bc4191ebfaf20321999823777d0fb20 (diff) | |
| parent | 9492dccb4a94cf266f05f0d7b47b5c1ce8daa272 (diff) | |
Merge pull request #5675 from jfcode4/master
Fix incorrect json encoding for control characters < 32
| -rw-r--r-- | core/io/util.odin | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/core/io/util.odin b/core/io/util.odin index 72983523a..a956a5975 100644 --- a/core/io/util.odin +++ b/core/io/util.odin @@ -189,6 +189,23 @@ write_escaped_rune :: proc(w: Writer, r: rune, quote: byte, html_safe := false, write_encoded_rune(w, r, false, &n) or_return return } + if r < 32 && for_json { + switch r { + case '\b': write_string(w, `\b`, &n) or_return + case '\f': write_string(w, `\f`, &n) or_return + case '\n': write_string(w, `\n`, &n) or_return + case '\r': write_string(w, `\r`, &n) or_return + case '\t': write_string(w, `\t`, &n) or_return + case: + write_byte(w, '\\', &n) or_return + write_byte(w, 'u', &n) or_return + write_byte(w, '0', &n) or_return + write_byte(w, '0', &n) or_return + write_byte(w, DIGITS_LOWER[r>>4 & 0xf], &n) or_return + write_byte(w, DIGITS_LOWER[r & 0xf], &n) or_return + } + return + } switch r { case '\a': write_string(w, `\a`, &n) or_return case '\b': write_string(w, `\b`, &n) or_return |