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

Function TestTruncatedMidKey

deep_spec_test.go:78–104  ·  view source on GitHub ↗

Verifies: SYS-REQ-043 [malformed] When JSON input is truncated mid-key (e.g. '{"a'), Get shall return a parse-related error and shall not panic.

(t *testing.T)

Source from the content-addressed store, hash-verified

76// When JSON input is truncated mid-key (e.g. '{"a'), Get shall return a
77// parse-related error and shall not panic.
78func TestTruncatedMidKey(t *testing.T) {
79 cases := []struct {
80 name string
81 data string
82 keys []string
83 }{
84 {name: "key not terminated", data: `{"a`, keys: []string{"a"}},
85 {name: "key with no colon", data: `{"abc"`, keys: []string{"abc"}},
86 {name: "second key truncated", data: `{"a":1,"b`, keys: []string{"b"}},
87 {name: "empty object start", data: `{`, keys: []string{"a"}},
88 }
89 for _, tc := range cases {
90 t.Run(tc.name, func(t *testing.T) {
91 func() {
92 defer func() {
93 if r := recover(); r != nil {
94 t.Fatalf("Get(%q, %v) panicked: %v", tc.data, tc.keys, r)
95 }
96 }()
97 _, _, _, err := Get([]byte(tc.data), tc.keys...)
98 if err == nil {
99 t.Fatalf("Get(%q, %v) should return error for truncated mid-key input", tc.data, tc.keys)
100 }
101 }()
102 })
103 }
104}
105
106// =============================================================================
107// Sentinel-value tests (SYS-REQ-044, SYS-REQ-045, SYS-REQ-046)

Callers

nothing calls this directly

Calls 1

GetFunction · 0.85

Tested by

no test coverage detected