Skip to content

Instantly share code, notes, and snippets.

@JLHwung
Last active June 10, 2020 02:08
Show Gist options
  • Save JLHwung/64fed33e2dbb3da7a18566fab26f045f to your computer and use it in GitHub Desktop.
Save JLHwung/64fed33e2dbb3da7a18566fab26f045f to your computer and use it in GitHub Desktop.
Safari console should not apply string normalization on pasteboard content

Intro

This is an example gist repo showcasing a bug that Safari applies string normalization when pasteboard content is applied

Reproduction

curl -o- https://gist.githubusercontent.com/JLHwung/64fed33e2dbb3da7a18566fab26f045f/raw/75a7be7ac00626e58ec93a90ade70909b1bd7fe1/test.js | pbcopy

Open Safari console, paste the copied contents.

Expected:

It should alert 1f7d.

Actual:

It alerts 3ce. (Safari)

Other browers:

Both Chrome and Firefox alert 1f7d as expected.

Is is a JSC bug?

No. If you save test.js and open by Safari, it alerts 1f7d as expected.

Reasoning

The ώ in source file is U+1F7D that has Singleton Decompositions, which means

String.fromCodePoint(0x1f7d).normalize() === String.fromCodePoint(0x3ce)

It prints incorrect code point because when the pasted source is excuted, U+1F7D has been normalized to U+03CE.

window.alert(("ώ").codePointAt(0).toString(16));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment