pickAdversarialPath produces a path that may NOT exist in v, including out-of-range indices and empty components — exactly the inputs that exposed PR #286 and the 8th empty-key panic.
(r *mathrand.Rand, v interface{})
| 303 | // out-of-range indices and empty components — exactly the inputs that |
| 304 | // exposed PR #286 and the 8th empty-key panic. |
| 305 | func pickAdversarialPath(r *mathrand.Rand, v interface{}) []string { |
| 306 | switch r.Intn(6) { |
| 307 | case 0: |
| 308 | return []string{""} // empty key — 8th panic site |
| 309 | case 1: |
| 310 | return []string{"[99]"} // out-of-range array index |
| 311 | case 2: |
| 312 | return []string{"missing_key_xyz"} // non-existent object key |
| 313 | case 3: |
| 314 | // Existing path + trailing empty. |
| 315 | base, _ := pickExistingPath(r, v) |
| 316 | return append(base, "") |
| 317 | case 4: |
| 318 | // Existing path + trailing out-of-range. |
| 319 | base, _ := pickExistingPath(r, v) |
| 320 | return append(base, "[99]") |
| 321 | default: |
| 322 | // A real existing path (control case). |
| 323 | base, _ := pickExistingPath(r, v) |
| 324 | return base |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // --------------------------------------------------------------------------- |
| 329 | // Comparison helpers — canonicalize both sides and compare bytes / values. |
no test coverage detected