Verifies: SYS-REQ-042 [malformed] When JSON input is truncated mid-structure (e.g. '{"a":[1,2'), Get shall return a parse-related error and shall not panic.
(t *testing.T)
| 45 | // When JSON input is truncated mid-structure (e.g. '{"a":[1,2'), Get shall |
| 46 | // return a parse-related error and shall not panic. |
| 47 | func TestTruncatedMidStructure(t *testing.T) { |
| 48 | cases := []struct { |
| 49 | name string |
| 50 | data string |
| 51 | keys []string |
| 52 | }{ |
| 53 | {name: "unclosed array", data: `{"a":[1,2`, keys: []string{"a"}}, |
| 54 | {name: "unclosed nested object", data: `{"a":{"b":`, keys: []string{"a"}}, |
| 55 | {name: "unclosed string value", data: `{"a":"hello`, keys: []string{"a"}}, |
| 56 | {name: "deeply nested unclosed", data: `{"a":{"b":{"c":[1`, keys: []string{"a"}}, |
| 57 | } |
| 58 | for _, tc := range cases { |
| 59 | t.Run(tc.name, func(t *testing.T) { |
| 60 | func() { |
| 61 | defer func() { |
| 62 | if r := recover(); r != nil { |
| 63 | t.Fatalf("Get(%q, %v) panicked: %v", tc.data, tc.keys, r) |
| 64 | } |
| 65 | }() |
| 66 | _, _, _, err := Get([]byte(tc.data), tc.keys...) |
| 67 | if err == nil { |
| 68 | t.Logf("Get(%q, %v) returned no error (best-effort parse)", tc.data, tc.keys) |
| 69 | } |
| 70 | }() |
| 71 | }) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Verifies: SYS-REQ-043 [malformed] |
| 76 | // When JSON input is truncated mid-key (e.g. '{"a'), Get shall return a |