| 175 | } |
| 176 | |
| 177 | static void test_json_bad_utf8(void) |
| 178 | { |
| 179 | const jsmntok_t *toks; |
| 180 | char *buf; |
| 181 | |
| 182 | buf = tal_strdup(tmpctx, "{\"1\":\"one\", \"2\":\"two\", \"3\":[\"three\", {\"deeper\": 17}]}"); |
| 183 | toks = json_parse_simple(tmpctx, buf, strlen(buf)); |
| 184 | assert(toks); |
| 185 | assert(toks->size == 3); |
| 186 | |
| 187 | assert(json_tok_streq(buf, &toks[1], "1")); |
| 188 | buf[toks[1].start] = 0xC0; |
| 189 | assert(!json_parse_simple(tmpctx, buf, strlen(buf))); |
| 190 | buf[toks[1].start] = '1'; |
| 191 | |
| 192 | assert(json_tok_streq(buf, &toks[2], "one")); |
| 193 | buf[toks[2].start] = 0xC0; |
| 194 | assert(!json_parse_simple(tmpctx, buf, strlen(buf))); |
| 195 | buf[toks[2].start] = 'o'; |
| 196 | |
| 197 | assert(json_tok_streq(buf, &toks[7], "three")); |
| 198 | buf[toks[7].start] = 0xC0; |
| 199 | assert(!json_parse_simple(tmpctx, buf, strlen(buf))); |
| 200 | buf[toks[7].start] = 't'; |
| 201 | |
| 202 | assert(json_parse_simple(tmpctx, buf, strlen(buf))); |
| 203 | } |
| 204 | |
| 205 | int main(int argc, char *argv[]) |
| 206 | { |
no test coverage detected