Skip to content

json cannot decode non-BMP character escapes #13064

Closed
@kmcallister

Description

@kmcallister

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions