| 199 | } |
| 200 | |
| 201 | static void test_json_bad_utf8(void) |
| 202 | { |
| 203 | const jsmntok_t *toks; |
| 204 | char *buf; |
| 205 | |
| 206 | buf = tal_strdup(tmpctx, "{\"1\":\"one\", \"2\":\"two\", \"3\":[\"three\", {\"deeper\": 17}]}"); |
| 207 | toks = json_parse_simple(tmpctx, buf, strlen(buf)); |
| 208 | assert(toks); |
| 209 | assert(toks->size == 3); |
| 210 | |
| 211 | assert(json_tok_streq(buf, &toks[1], "1")); |
| 212 | buf[toks[1].start] = 0xC0; |
| 213 | assert(!json_parse_simple(tmpctx, buf, strlen(buf))); |
| 214 | buf[toks[1].start] = '1'; |
| 215 | |
| 216 | assert(json_tok_streq(buf, &toks[2], "one")); |
| 217 | buf[toks[2].start] = 0xC0; |
| 218 | assert(!json_parse_simple(tmpctx, buf, strlen(buf))); |
| 219 | buf[toks[2].start] = 'o'; |
| 220 | |
| 221 | assert(json_tok_streq(buf, &toks[7], "three")); |
| 222 | buf[toks[7].start] = 0xC0; |
| 223 | assert(!json_parse_simple(tmpctx, buf, strlen(buf))); |
| 224 | buf[toks[7].start] = 't'; |
| 225 | |
| 226 | assert(json_parse_simple(tmpctx, buf, strlen(buf))); |
| 227 | } |
| 228 | |
| 229 | int main(int argc, char *argv[]) |
| 230 | { |
no test coverage detected