Skip to content

fix: preserve Unicode surrogate pairs during slugification - #217

Open
ilovesugarr wants to merge 1 commit into
simov:masterfrom
ilovesugarr:fix/unicode-surrogate-pairs
Open

fix: preserve Unicode surrogate pairs during slugification#217
ilovesugarr wants to merge 1 commit into
simov:masterfrom
ilovesugarr:fix/unicode-surrogate-pairs

Conversation

@ilovesugarr

Copy link
Copy Markdown

Summary

Fix Unicode surrogate pair handling by replacing split('') with Array.from() when iterating normalized strings.

Motivation

JavaScript strings are UTF-16 encoded, and split('') splits non-BMP characters such as emojis into separate surrogate halves. This prevents slugify.extend() from matching characters like emojis and may corrupt their handling.

Implementation

Use Array.from(string.normalize()) so iteration happens by Unicode code points instead of UTF-16 code units.

Testing

Added tests covering:

  • surrogate pair characters
  • emoji handling
  • slugify.extend() mappings with non-BMP characters

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant