Skip to content

[Bug]: diffStrings breaks surrogate pairsΒ #15384

Open
@gofr

Description

@gofr

Version

29.7.0

Steps to reproduce

test('Surrogate pairs', () => {
  expect('😞').toBe('πŸ˜„');
});

Expected behavior

expect(received).toBe(expected) // Object.is equality

Expected: "πŸ˜„"
Received: "😞"

Actual behavior

Both emojis are made up of surrogate pairs. They have the same high surrogate. When the output contains colors, the low surrogate character is highlighted separately from the high surrogate character, injecting ANSI control sequence characters between the two halves of the surrogate pair, resulting in output like this:

expect(received).toBe(expected) // Object.is equality

Expected: "οΏ½οΏ½"
Received: "οΏ½οΏ½"

Additional context

No response

Environment

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.11.1/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 9.11.0 - ~/.local/share/pnpm/pnpm

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions