Verifies: SYS-REQ-014 [differential] — for a corpus of lone-surrogate inputs, ParseString must byte-match encoding/json.Unmarshal (the oracle exercised by the FuzzJSONStructureAware checkParseStringGate finder).
(t *testing.T)
| 292 | // inputs, ParseString must byte-match encoding/json.Unmarshal (the oracle |
| 293 | // exercised by the FuzzJSONStructureAware checkParseStringGate finder). |
| 294 | func TestParseStringLoneSurrogateMatchesEncodingJSON(t *testing.T) { |
| 295 | corpus := []string{ |
| 296 | `\uDB29`, |
| 297 | `\uDB29A7FA`, |
| 298 | `\uDB29A7FA71 a`, |
| 299 | `\uD800`, |
| 300 | `\uD83D`, |
| 301 | `\uDBFF`, |
| 302 | `\uDC00`, |
| 303 | `\uDFFF`, |
| 304 | `\uDE03`, |
| 305 | `\uD800\u0041`, |
| 306 | `\uD800\uD800`, |
| 307 | `\uD800\uDBFF`, |
| 308 | `\uD800\uE000`, |
| 309 | `\uD800\uFFFF`, |
| 310 | `\uDB29\uDC00`, |
| 311 | `\uD83D\uDE03 more`, |
| 312 | `\uD800\uDC00`, |
| 313 | `\u0000\uD800\u0000`, |
| 314 | } |
| 315 | for _, esc := range corpus { |
| 316 | // Reference oracle: encoding/json unescapes the quoted string. |
| 317 | var want string |
| 318 | jsonInput := `"` + esc + `"` |
| 319 | if err := json.Unmarshal([]byte(jsonInput), &want); err != nil { |
| 320 | // encoding/json rejects malformed escapes (e.g. truncated "\u"). The |
| 321 | // corpus above is chosen to all be accepted; if one is rejected we |
| 322 | // want to know rather than silently skip. |
| 323 | t.Errorf("encoding/json rejected corpus input %q: %v", jsonInput, err) |
| 324 | continue |
| 325 | } |
| 326 | |
| 327 | got, err := ParseString([]byte(esc)) |
| 328 | if err != nil { |
| 329 | t.Errorf("ParseString(%q) returned error %v; encoding/json accepted it as %q", esc, err, want) |
| 330 | continue |
| 331 | } |
| 332 | if got != want { |
| 333 | t.Errorf("ParseString(%q) divergence:\n got = %q (% x)\n want = %q (% x)", |
| 334 | esc, got, []byte(got), want, []byte(want)) |
| 335 | } |
| 336 | } |
| 337 | } |
nothing calls this directly
no test coverage detected