Key-value pairs *must* be strings with size 1. */
| 337 | } |
| 338 | /* Key-value pairs *must* be strings with size 1. */ |
| 339 | static inline const jsmntok_t * |
| 340 | validate_jsmn_keyvalue(const char *buf, |
| 341 | const jsmntok_t *p, |
| 342 | const jsmntok_t *end, |
| 343 | bool *valid) |
| 344 | { |
| 345 | if (p >= end) { |
| 346 | *valid = false; |
| 347 | return p; |
| 348 | } |
| 349 | |
| 350 | /* Check key. |
| 351 | * |
| 352 | * JSMN parses the syntax `"key": "value"` as a |
| 353 | * JSMN_STRING of size 1, containing the value |
| 354 | * datum as a sub-datum. |
| 355 | * |
| 356 | * Thus, keys in JSON objects are really strings |
| 357 | * that "contain" the value, thus we check if |
| 358 | * the size is 1. |
| 359 | * |
| 360 | * JSMN supports a non-standard syntax such as |
| 361 | * `"key": 1 2 3 4`, which it considers as a |
| 362 | * string object that contains a sequence of |
| 363 | * sub-datums 1 2 3 4. |
| 364 | * The check below that p->size == 1 also |
| 365 | * incidentally rejects that non-standard |
| 366 | * JSON. |
| 367 | */ |
| 368 | if (p->type != JSMN_STRING || p->size != 1 |
| 369 | || !utf8_check(buf + p->start, p->end - p->start)) { |
| 370 | *valid = false; |
| 371 | return p; |
| 372 | } |
| 373 | |
| 374 | ++p; |
| 375 | return validate_jsmn_datum(buf, p, end, valid); |
| 376 | } |
| 377 | |
| 378 | /** validate_jsmn_parse_output |
| 379 | * |
no test coverage detected