Skip to content

serialize::json::Encoder emit_char serializes extra nulls #19719

Closed
@emk

Description

@emk

The following code snippet:

extern crate serialize;

fn main() {
    let s = serialize::json::encode(&'c');
    println!("Encoded: {}, bytes: {}", s, s.as_bytes());
    assert_eq!("\"c\"", s.as_slice());
}

Produces the following output:

Encoded: "c", bytes: [34, 99, 0, 0, 0, 34]
task '<main>' panicked at 'assertion failed: `(left == right) && (right == left)` (left: `"c"`, right: `"c"`)', <anon>:6
playpen: application terminated with error code 101

The serialized string should be [34, 99, 34], and not [34, 99, 0, 0, 0, 34].

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