Skip to content

Fix MapKey::deserialize_bool invalid UTF-8 on malformed boolean keys - #1367

Closed
young1lin wants to merge 1 commit into
serde-rs:masterfrom
young1lin:cursor/fix-mapkey-bool-fallback-fe90
Closed

young1lin wants to merge 1 commit into
serde-rs:masterfrom
young1lin:cursor/fix-mapkey-bool-fallback-fe90

Conversation

@young1lin

Copy link
Copy Markdown

Fixes #1364

OpenJobs listing: 2abe1ca8-ece3-402d-b5d0-85312697221d
Via openjobs.bot
https://openjobs.bot/jobs/2abe1ca8-ece3-402d-b5d0-85312697221d

Summary

In MapKey::deserialize_bool, use peek() and only eat_char() on the t/f branches so the invalid-key fallback runs parse_str from the start of the key (same pattern as numeric map keys). Avoids constructing invalid UTF-8 from continuation bytes.

Test plan

cargo test test_boolean_key   # 2 passed
cargo test                    # full suite green

Added test_boolean_key_invalid covering multibyte invalid key {"éx": 1}, ASCII invalid {"yes": 1}, empty key; from_str / from_slice / from_reader.

Commit: a7045d3

Use peek() instead of next_char() before matching true/false so the
fallback parse_str path reads the full key. Avoids invalid UTF-8 in
error messages for multibyte keys and fixes empty-key edge cases.

Fixes serde-rs#1364

Co-authored-by: young1lin <young1lin@users.noreply.github.com>
@young1lin

Copy link
Copy Markdown
Author

Closing — withdrawing OpenJobs-related submission.

@young1lin young1lin closed this Nov 3, 2026
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.

MapKey::deserialize_bool parses a key from a UTF-8 continuation byte, building an invalid &str in safe code

2 participants