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)
| 679 | // truncated_mid_element class: the parser must not read past the cut when |
| 680 | // scanning for the element's value type. |
| 681 | func 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 |
nothing calls this directly
no outgoing calls
no test coverage detected