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

Function genPathComponent

json_fuzz_test.go:945–972  ·  view source on GitHub ↗

genPathComponent returns a single adversarial path component.

(r *rand.Rand)

Source from the content-addressed store, hash-verified

943
944// genPathComponent returns a single adversarial path component.
945func genPathComponent(r *rand.Rand) string {
946 switch r.Intn(12) {
947 case 0: // empty string (SYS-REQ-111 hazard — the 8th-panic class)
948 return ""
949 case 1: // valid array index in range
950 return "[" + strconv.Itoa(r.Intn(5)) + "]"
951 case 2: // out-of-range array index (SYS-REQ-110 hazard)
952 return "[99]"
953 case 3: // very large array index
954 return "[999999]"
955 case 4: // malformed array index syntax (empty brackets)
956 return "[]"
957 case 5: // negative index
958 return "[-1]"
959 case 6: // unicode key
960 return "すびほ"
961 case 7: // key with a byte requiring JSON escaping in output
962 return "a\"b"
963 case 8: // "key" (matches seed corpus)
964 return "key"
965 case 9: // "a" (common test key)
966 return "a"
967 case 10: // long ASCII key
968 return "abcdefghij"
969 default: // single ASCII char
970 return string(rune('a' + r.Intn(26)))
971 }
972}
973
974// injectPathHazard randomly injects an adversarial path component into an
975// existing path. This implements the injectEmptyKeyComponent and

Callers 1

genKeyPathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected