MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / FuzzUnmarshalKeyComparison

Function FuzzUnmarshalKeyComparison

internal/json/json_test.go:143–174  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

141}
142
143func FuzzUnmarshalKeyComparison(f *testing.F) {
144 // Add seed corpus for expected valid key and the known problematic cases.
145 f.Add("field")
146 f.Add("FIELD")
147 f.Add("field\x00")
148
149 f.Fuzz(func(t *testing.T, key string) {
150 // Generate valid JSON with the fuzzed key.
151 // json.Encoder ensures the key is properly escaped (e.g. \x00 becomes \u0000).
152 var buf bytes.Buffer
153 enc := json.NewEncoder(&buf)
154 enc.SetEscapeHTML(false)
155 if err := enc.Encode(key); err != nil {
156 return
157 }
158 encodedKey := buf.Bytes()
159 jsonData := fmt.Sprintf(`{%s: "value"}`, encodedKey)
160
161 type Target struct {
162 Field string `json:"field"`
163 }
164
165 var got Target
166 if err := Unmarshal([]byte(jsonData), &got); err != nil {
167 return
168 }
169
170 if got.Field == "value" && key != "field" {
171 t.Errorf("Unmarshal matched key %q (JSON: %s) to field 'field'", key, encodedKey)
172 }
173 })
174}
175
176func FuzzUnmarshalFieldIsolation(f *testing.F) {
177 // Add seed corpus.

Callers

nothing calls this directly

Calls 2

UnmarshalFunction · 0.85
BytesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…