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

Function pathShapeMatchesRoot

path_fuzz_test.go:417–472  ·  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

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

Callers 3

FuzzPathMutationFunction · 0.85
pathShapeMatchesDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected