Key-value pairs *must* be strings with size 1. */
| 380 | } |
| 381 | /* Key-value pairs *must* be strings with size 1. */ |
| 382 | static inline const jsmntok_t * |
| 383 | validate_jsmn_keyvalue(const char *buf, |
| 384 | const jsmntok_t *p, |
| 385 | const jsmntok_t *end, |
| 386 | bool *valid) |
| 387 | { |
| 388 | if (p >= end) { |
| 389 | *valid = false; |
| 390 | return p; |
| 391 | } |
| 392 | |
| 393 | /* Check key. |
| 394 | * |
| 395 | * JSMN parses the syntax `"key": "value"` as a |
| 396 | * JSMN_STRING of size 1, containing the value |
| 397 | * datum as a sub-datum. |
| 398 | * |
| 399 | * Thus, keys in JSON objects are really strings |
| 400 | * that "contain" the value, thus we check if |
| 401 | * the size is 1. |
| 402 | * |
| 403 | * JSMN supports a non-standard syntax such as |
| 404 | * `"key": 1 2 3 4`, which it considers as a |
| 405 | * string object that contains a sequence of |
| 406 | * sub-datums 1 2 3 4. |
| 407 | * The check below that p->size == 1 also |
| 408 | * incidentally rejects that non-standard |
| 409 | * JSON. |
| 410 | */ |
| 411 | if (p->type != JSMN_STRING || p->size != 1 |
| 412 | || !utf8_check(buf + p->start, p->end - p->start)) { |
| 413 | *valid = false; |
| 414 | return p; |
| 415 | } |
| 416 | |
| 417 | ++p; |
| 418 | return validate_jsmn_datum(buf, p, end, valid); |
| 419 | } |
| 420 | |
| 421 | /** validate_jsmn_parse_output |
| 422 | * |
no test coverage detected