Skip to content

utf16_chars() and from_utf16() stop on 0_u16 #12316

Closed
@SimonSapin

Description

@SimonSapin

When the input contains a zero, these functions stop and ignore the rest of the input instead of emitting a perfectly valid U+0000 code point.

Test case:

use std::str;

fn main() {
    let a = "foo\0bar";
    let b = a.to_utf16();
    let c = str::from_utf16(b);
    println!("{:?}", a);
    println!("{:?}", b);
    println!("{:?}", c)
}

Output:

"foo\x00bar"
~[102u16, 111u16, 111u16, 0u16, 98u16, 97u16, 114u16]
~"foo"

Expected output:

"foo\x00bar"
~[102u16, 111u16, 111u16, 0u16, 98u16, 97u16, 114u16]
~"foo\x00bar"

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