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

Function truncateMidStructure

json_fuzz_test.go:631–644  ·  view source on GitHub ↗

truncateMidStructure cuts after an unclosed '{' or '['. This is the truncated_mid_structure class: the parser must detect the missing closing token and return a clean MalformedObjectError / MalformedArrayError.

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

Source from the content-addressed store, hash-verified

629// truncated_mid_structure class: the parser must detect the missing closing
630// token and return a clean MalformedObjectError / MalformedArrayError.
631func truncateMidStructure(r *rand.Rand, data []byte) []byte {
632 pos := findStructuralBytes(data, '{', '[')
633 if len(pos) == 0 {
634 return data
635 }
636 open := pos[r.Intn(len(pos))]
637 if open+1 >= len(data) {
638 return data
639 }
640 cut := open + 1 + r.Intn(len(data)-open-1)
641 out := make([]byte, cut)
642 copy(out, data[:cut])
643 return out
644}
645
646// truncateMidEscape cuts inside a \uXXXX escape sequence. This is the
647// truncated_escape_sequence class: the parser's Unescape routine must

Callers

nothing calls this directly

Calls 1

findStructuralBytesFunction · 0.85

Tested by

no test coverage detected