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)
| 629 | // truncated_mid_structure class: the parser must detect the missing closing |
| 630 | // token and return a clean MalformedObjectError / MalformedArrayError. |
| 631 | func 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 |
nothing calls this directly
no test coverage detected