Repository navigation
Commit 2560d0b
committed
fix: integer map keys when deserializing from a Value
Deserializing from an owned or borrowed Value by value
(`from_owned_value`, `from_borrowed_value`, `Value::deserialize_*`)
passed each object key as `Value::String`, so integer keys never parsed:
let v = to_owned_value(br#"{"1":2}"#)?;
from_owned_value::<BTreeMap<i64, u8>>(v)
Err(invalid type: string "1", expected i64)
The by-reference path (`from_refowned_value`) and the text path accept
it, and so do serde_json and sonic-rs. Keys now go through
`MapKeyDeserializer` in all four Value paths; its constructor takes
`impl Into<Cow<str>>`, so one `new` serves borrowed and owned keys.
Test: `value_map_integer_keys`; `integer_keys_follow_json_number_syntax`
and `i128_map_keys` now also check the by-value paths (all through the
same `map_key_results` helper: `from_slice` and the four Value
functions). Fails before this change.
Found by a differential fuzzer (serde_json, simd-json, sonic-rs, jiter).1 parent d7c46bf commit 2560d0b
4 files changed
Lines changed: 30 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
| 234 | + | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| |||
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
272 | | - | |
| 273 | + | |
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
| 220 | + | |
| 221 | + | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| |||
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
259 | | - | |
| 260 | + | |
| 261 | + | |
260 | 262 | | |
261 | 263 | | |
262 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 38 | + | |
| 39 | + | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1450 | 1450 | | |
1451 | 1451 | | |
1452 | 1452 | | |
1453 | | - | |
1454 | | - | |
1455 | | - | |
| 1453 | + | |
1456 | 1454 | | |
1457 | 1455 | | |
1458 | 1456 | | |
| |||
1464 | 1462 | | |
1465 | 1463 | | |
1466 | 1464 | | |
1467 | | - | |
| 1465 | + | |
1468 | 1466 | | |
1469 | 1467 | | |
1470 | 1468 | | |
1471 | 1469 | | |
1472 | | - | |
1473 | | - | |
1474 | | - | |
| 1470 | + | |
1475 | 1471 | | |
1476 | 1472 | | |
1477 | | - | |
1478 | | - | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
1482 | 1477 | | |
1483 | | - | |
1484 | | - | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
1485 | 1481 | | |
1486 | 1482 | | |
1487 | 1483 | | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
0 commit comments