Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json cannot decode non-BMP character escapes #13064

Closed
kmcallister opened this issue Mar 22, 2014 · 2 comments
Closed

json cannot decode non-BMP character escapes #13064

kmcallister opened this issue Mar 22, 2014 · 2 comments

Comments

@kmcallister
Copy link
Contributor

Per RFC 4627:

To escape an extended character that is not in the Basic Multilingual Plane, the character is represented as a twelve-character sequence, encoding the UTF-16 surrogate pair. So, for example, a string containing only the G clef character (U+1D11E) may be represented as "\uD834\uDD1E".

(This is a legacy of JavaScript's UCS-2 string semantics.)

Rust's serialize::json does not decode these escapes properly:

extern crate serialize;

use serialize::json;

fn main() {
    println!("{:?}", json::from_str("\"\\ud83d\\udca9\""));
}

produces

task '<main>' failed at 'called `Option::unwrap()` on a `None` value'
kmcallister added a commit to servo/html5ever that referenced this issue Mar 22, 2014
kmcallister added a commit to servo/html5ever that referenced this issue Mar 26, 2014
@kmcallister
Copy link
Contributor Author

I'm working on this.

@pnkfelix
Copy link
Member

Nical has a long open PR with a rewrite of JSO to make it streaming. Might be good to coordinate changes here

bors added a commit that referenced this issue Apr 13, 2014
This fixes two separate issues related to character encoding.

* Add `encode_utf16` to the `Char` trait, analogous to `encode_utf8`.  `&str` already supports UTF-16 encoding but only with a heap allocation.  Also fix `encode_utf8` docs and add tests.

* Correctly decode non-BMP hex escapes in JSON (#13064).
@bors bors closed this as completed in cee9a83 Apr 13, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue Aug 23, 2022
Log rustfmt parsing errors as warnings

We unconditionally pass an edition parameter to rustfmt, for some crates
this might fail rustfmt so instead of swallowing the error, at least Log
it on a level that is logged by default so users won't be completely
confused about it.
See for context rust-lang/rust-analyzer#10209

Closes rust-lang/rust-analyzer#10209
flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 11, 2024
…rednet

Reduce the size of lintcheck JSON output

Saves about 80% of the size by picking out what we need rather than serialising the whole diagnostic

r? `@xFrednet`

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants