MCPcopy
hub / github.com/buger/jsonparser / TestSetTruncatedInput

Function TestSetTruncatedInput

deep_spec_test.go:319–344  ·  view source on GitHub ↗

============================================================================= Set truncation and edge cases (SYS-REQ-051, SYS-REQ-068, SYS-REQ-069, SYS-REQ-070) ============================================================================= Verifies: SYS-REQ-051 [malformed] Set on truncated input shal

(t *testing.T)

Source from the content-addressed store, hash-verified

317// Verifies: SYS-REQ-051 [malformed]
318// Set on truncated input shall return an error rather than corrupt output or panic.
319func TestSetTruncatedInput(t *testing.T) {
320 cases := []struct {
321 name string
322 data string
323 keys []string
324 }{
325 {name: "truncated object", data: `{"a":`, keys: []string{"a"}},
326 {name: "truncated nested", data: `{"a":{"b":`, keys: []string{"a", "b"}},
327 {name: "malformed colon chain", data: `{"a"::"b"}`, keys: []string{"a"}},
328 }
329 for _, tc := range cases {
330 t.Run(tc.name, func(t *testing.T) {
331 func() {
332 defer func() {
333 if r := recover(); r != nil {
334 t.Fatalf("Set(%q, %v) panicked: %v", tc.data, tc.keys, r)
335 }
336 }()
337 _, err := Set([]byte(tc.data), []byte(`"new"`), tc.keys...)
338 if err == nil {
339 t.Logf("Set(%q, %v) succeeded (may be valid path creation)", tc.data, tc.keys)
340 }
341 }()
342 })
343 }
344}
345
346// Verifies: SYS-REQ-068 [boundary]
347// Set with path pointing beyond EOF shall return error, not panic.

Callers

nothing calls this directly

Calls 1

SetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…