Skip to content

Array.from(str) returns [] for any string containing a lone surrogate #9431

Description

@proggeramlug
Array.from("a\ud83db")   // node: 3 elements   perry: []
[..."a\ud83db"]          // correct in both

js_array_from_string_codepoints (array/alloc.rs:359) does str::from_utf8(bytes) and returns an empty array on Err — but perry's string payloads are WTF-8, so any lone surrogate makes the whole conversion silently yield nothing. The spread and for…of paths on the same string are correct, which is what makes this a wrong answer rather than a consistent limitation.

Silent: no error, just an empty array where the program expects characters.

Fix note

The walk should use wtf8_step like the other iterators. It was left out of #9427 because that same function holds a raw elements pointer and a borrow of the source payload across per-element allocations — pre-existing, but it means the change wants the RuntimeHandleScope discipline string/split.rs uses rather than a one-line swap.

Found while fixing #9409.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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