Commit 4af2f87
committed
fix(api): guard GET from JSON body extraction, throw on key conflicts, simplify tryParseJsonField
Addresses BugBot review comments:
- GET + bare JSON raw-field: buildFromFields now skips extractJsonBody for
GET requests, so a JSON-shaped raw-field falls through to query-param
routing (which throws a clear ValidationError) rather than silently
creating a GET body.
- Shallow merge key conflict: when auto-detected JSON body and field flags
share a top-level key, throw ValidationError before merging. A shallow
spread would silently drop nested data (e.g. statusDetails.ignoreCount
lost when statusDetails[minCount]=5 is also passed). Suggest --data/-d.
Simplify tryParseJsonField by removing the redundant startsWith check —
JSON.parse handles non-JSON strings via the catch branch; the check was
just an optimization that added noise. Note: the startsWith guard in
normalizeFields is intentionally kept (broader than JSON.parse — it protects
malformed-but-JSON-shaped strings like {broken:json} from colon mangling).1 parent 20fa499 commit 4af2f87
2 files changed
+75
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
636 | 636 | | |
637 | 637 | | |
638 | 638 | | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | 639 | | |
643 | 640 | | |
644 | 641 | | |
| |||
652 | 649 | | |
653 | 650 | | |
654 | 651 | | |
655 | | - | |
656 | | - | |
| 652 | + | |
| 653 | + | |
657 | 654 | | |
658 | 655 | | |
659 | 656 | | |
| |||
889 | 886 | | |
890 | 887 | | |
891 | 888 | | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
896 | 897 | | |
897 | 898 | | |
898 | 899 | | |
| |||
905 | 906 | | |
906 | 907 | | |
907 | 908 | | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
908 | 924 | | |
909 | 925 | | |
910 | 926 | | |
911 | | - | |
| 927 | + | |
912 | 928 | | |
913 | 929 | | |
914 | 930 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1416 | 1416 | | |
1417 | 1417 | | |
1418 | 1418 | | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
1419 | 1468 | | |
0 commit comments