Skip to content

Commit 548cdc2

Browse files
committed
Handle non-printable control characters when escaping JSON
1 parent ebcdbc5 commit 548cdc2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

analysis/vendor/json/Json.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ let escape text =
141141
| '\b' -> Buffer.add_string buf "\\b"
142142
| '\r' -> Buffer.add_string buf "\\r"
143143
| '\t' -> Buffer.add_string buf "\\t"
144-
| c -> Buffer.add_char buf c);
144+
| c ->
145+
let code = Char.code c in
146+
if code < 0x20 then Printf.bprintf buf "\\u%04x" code
147+
else Buffer.add_char buf c);
145148
loop (i + 1))
146149
in
147150
loop 0;

0 commit comments

Comments
 (0)