Repository navigation
fix(engine): accept lone surrogate escapes in JSON.parse - #5578
Merged
HalidOdat merged 1 commit intoOct 12, 2026
Merged
Conversation
JSON.parse validated its input by deserializing it into a serde_json::Value, which builds Rust strings and so rejects lone surrogate escapes such as "\ud83d", although they are valid JSON. Only check the syntax, with serde::de::IgnoredAny; Boa's own JSON parser then builds the UTF-16 strings. Fixes #5576
Test262 conformance changes
Fixed tests (1):Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5578 +/- ##
===========================================
+ Coverage 47.24% 63.00% +15.76%
===========================================
Files 476 536 +60
Lines 46892 60315 +13423
===========================================
+ Hits 22154 38003 +15849
+ Misses 24738 22312 -2426 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
HalidOdat
approved these changes
Oct 12, 2026
HalidOdat
left a comment
Member
There was a problem hiding this comment.
Looks perfect to me! Thank you for the contribution!😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request fixes/closes #5576.
It changes the following:
JSON.parsechecked that its input is valid JSON by deserializing it into aserde_json::Value. That builds RustStrings, so lone surrogate escapes such as"\ud83d"were rejected (unexpected end of hex escape), although they are valid JSON (ECMA-404) andJSON.parsemust return a one-code-unit string for them.serde_json::from_str::<serde::de::IgnoredAny>, which only validates the syntax without decoding strings into RustStrings. Boa's own JSON-mode parser, which already ran afterwards, builds the actual UTF-16 strings, so lone surrogates come through correctly. Invalid JSON still throws aSyntaxErrorwith serde's message.json_parse_lone_surrogate_escapes, which checks a lone high surrogate, a lone low surrogate, one inside an array, and a valid surrogate pair. Also addedjson_parse_invalid_text_still_throws_syntax_errorfor an incomplete\uescape.Testing:
cargo test -p boa_engine --lib json→ 44 passed. Before the change, the new test fails withUncaught SyntaxError: unexpected end of hex escape at line 1 column 8.cargo fmt --checkis clean.The repo's pre-push hook (
cargo make run-ci: fmt check + clippy with all features and with no features) passes.