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

Function truncateMidElement

json_fuzz_test.go:681–696  ·  view source on GitHub ↗

truncateMidElement cuts inside an array element, after a '[' or ','. The truncated_mid_element class: the parser must not read past the cut when scanning for the element's value type.

(r *rand.Rand, data []byte)

Source from the content-addressed store, hash-verified

679// truncated_mid_element class: the parser must not read past the cut when
680// scanning for the element's value type.
681func truncateMidElement(r *rand.Rand, data []byte) []byte {
682 var pos []int
683 for i, b := range data {
684 if (b == '[' || b == ',') && i+2 < len(data) {
685 pos = append(pos, i)
686 }
687 }
688 if len(pos) == 0 {
689 return data
690 }
691 anchor := pos[r.Intn(len(pos))]
692 cut := anchor + 1 + r.Intn(len(data)-anchor-1)
693 out := make([]byte, cut)
694 copy(out, data[:cut])
695 return out
696}
697
698// duplicateKey injects a duplicate object key, turning {"k":1} into
699// {"k":1,"k":1}. This exercises duplicate-key handling: the parser should

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected