Skip to content

test: cover malformed UTF-8 sequences in strings and keys - #1337

Open
VedantMadane wants to merge 3 commits into
serde-rs:masterfrom
VedantMadane:test/issue-1185-invalid-utf8
Open

VedantMadane wants to merge 3 commits into
serde-rs:masterfrom
VedantMadane:test/issue-1185-invalid-utf8

Conversation

@VedantMadane

Copy link
Copy Markdown

Summary

Adds focused regression tests for malformed UTF-8 inside JSON strings and object keys when deserializing via from_slice into Value and String (issue #1185).

Why

#1185 asks for stronger coverage of intentionally invalid UTF-8 after performance-oriented parsing changes. Existing coverage had a single test_raw_invalid_utf8 case; this expands that to truncated multi-byte sequences, invalid continuations, overlong encodings, bad lead bytes, and bad object keys.

Tests

  • test_invalid_utf8_sequences_in_strings — 9 malformed payloads; asserts invalid unicode code point and that Value/String diagnostics match
  • test_invalid_utf8_in_object_keys — rejects bad UTF-8 in map keys

Completeness

No production code stubs. Tests only; behavior is reject-with-error (existing correct path).

Fixes #1185

Add regression coverage for truncated multi-byte sequences, invalid
continuation bytes, overlong encodings, and bad lead bytes when
deserializing into Value and String via from_slice (issue serde-rs#1185).

Also reject invalid UTF-8 in object keys.

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
\xC2\x00 is reported as a control character (0x00-0x1F) before UTF-8
validation, which failed nightly and Miri. Use \xC2\x7F instead so the
case asserts the invalid-unicode diagnostic.

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Adding tests of invalid utf-8

1 participant