Commit b1ac6fe
json_esc1: do not truncate length-delimited strings at an embedded NUL
The escape scan stopped on `(c = *s)`, treating a NUL byte as a string
terminator even when an explicit length was supplied -- silently
dropping everything from the first embedded NUL onward. Remove the NUL
guard from the loop condition: slen and max_output_size bound the loop,
NUL-terminated callers pass slen == strlen so they still stop at the NUL
exactly, and an embedded NUL is now emitted as its six-character unicode
hex escape via the existing control-character (JSON_ESC_CHAR) path.
tests: add strn-embedded-nul and keyn-embedded-nul, which write a
length-delimited value/key containing a NUL and assert it is escaped
(both fail against the pre-fix truncating scan). Suite: 52/52.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 1fd2b75 commit b1ac6fe
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
213 | 229 | | |
214 | 230 | | |
215 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
| |||
0 commit comments