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

Function pathShapeMatchesRoot

path_fuzz_test.go:411–466  ·  view source on GitHub ↗

pathShapeMatchesRoot reports whether the path is semantically applicable to the JSON data's container structure. Used to gate the json.Valid post-condition for Set/Delete. Returns false (soft-skip the post-condition) when ANY of these documented-open-bug conditions hold: - First component is array

(data []byte, path []string)

Source from the content-addressed store, hash-verified

409// For all other shapes — including out-of-range valid-syntax indices and
410// unknown object keys — the post-condition is asserted.
411func pathShapeMatchesRoot(data []byte, path []string) bool {
412 if len(path) == 0 {
413 return true
414 }
415 // Empty-string components anywhere in the path → documented bug class.
416 for _, c := range path {
417 if c == "" {
418 return false
419 }
420 // Keys containing bytes that require JSON escaping → D10.
421 for i := 0; i < len(c); i++ {
422 b := c[i]
423 if b == '"' || b == '\\' || b < 0x20 {
424 return false
425 }
426 }
427 // Malformed array-index syntax → KI-3 variant. A component that
428 // starts with '[' but is not exactly '[' + digits + ']' (e.g. "[]",
429 // "[abc]", "[1") is treated as isIndex by createInsertComponent
430 // but produces malformed JSON output when spliced into an object
431 // body. Same hazard class as a well-formed [N] under an object
432 // parent (KI-3 proper); skip the json.Valid post-condition until
433 // the type-mismatch guard lands.
434 if len(c) > 0 && c[0] == '[' {
435 if len(c) < 3 || c[len(c)-1] != ']' {
436 return false
437 }
438 for i := 1; i < len(c)-1; i++ {
439 if c[i] < '0' || c[i] > '9' {
440 return false
441 }
442 }
443 }
444 }
445 // Find first non-whitespace byte.
446 rootByte := byte(0)
447 for _, b := range data {
448 switch b {
449 case ' ', '\t', '\n', '\r':
450 continue
451 default:
452 rootByte = b
453 goto found
454 }
455 }
456 return false
457found:
458 isArrayIdx := len(path[0]) > 0 && path[0][0] == '['
459 if isArrayIdx && rootByte != '[' {
460 return false // array-index path on non-array root — D6
461 }
462 if !isArrayIdx && rootByte == '[' {
463 return false // object-key path on array root — also undefined
464 }
465 return true
466}
467
468// =============================================================================

Callers 3

FuzzPathMutationFunction · 0.85
pathShapeMatchesDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected