Skip to content

JS implementation for String.copyTo doesn't copy some esoteric Characters correctlyย #794

@ASzc

Description

@ASzc

I have been working on eclipse-archived/ceylon-sdk#449, and found that this string: ๐€€๔ฟฝ๔ฟฝ encodes fine on the JVM but is partially incorrect on JS (too short and distorted near the end). Single characters and longer strings of more common characters work fine.

I've traced this to CharacterBuffer.array, which is an Array<Character> populated from a String by a call to String.copyTo

Printing the String literal and printing CharacterBuffer.array after copyTo:

JVM:

๐€€๔ฟฝ๔ฟฝ
{ ๐€€, ๔ฟฝ, ๔ฟฝ }

JS:

๐€€๔ฟฝ๔ฟฝ
{ ๐€€, ๔ฟฝ, ๏ฟฝ }

If I swap out string.copyTo(array); for:

for (i->c in string.indexed) {
    array.set(i, c);
}

Then JS returns (the same as JVM):

๐€€๔ฟฝ๔ฟฝ
{ ๐€€, ๔ฟฝ, ๔ฟฝ }

The native JS implementation looks equivalent to the above Ceylon, but perhaps there's some subtle error?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions