MCPcopy Create free account
hub / github.com/buger/jsonparser / pickAdversarialPath

Function pickAdversarialPath

reference_oracle_test.go:305–326  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

303// out-of-range indices and empty components — exactly the inputs that
304// exposed PR #286 and the 8th empty-key panic.
305func 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.

Callers 2

TestOracleGetRoundTripFunction · 0.85
TestOracleSetRoundTripFunction · 0.85

Calls 1

pickExistingPathFunction · 0.85

Tested by

no test coverage detected