Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

putting emoji's HTML entities emits square boxes instead of actual emoji #235

Open
gaeulbyul opened this issue Dec 17, 2019 · 3 comments
Open
Labels

Comments

@gaeulbyul
Copy link

Input:

<div>&#x1F408;&#x1F415;&#128007;&#128017;</div>;

Expected:

React.createElement( 'div', null, "🐈🐕🐇🐑" );

Actual:

React.createElement( 'div', null, "" );
@mourner
Copy link
Collaborator

mourner commented Dec 28, 2019

Not sure how this is related to Buble. Can you share a test case from https://buble.surge.sh/?

@gaeulbyul
Copy link
Author

When I insert emoji in HTML entity like this, Buble decodes it to square box character instead of intended emoji.

For example, inserting <div>&#x1F408;&#x1F415;&#128007;&#128017;</div> transforms into React.createElement( 'div', null, "" ) but I think it would be React.createElement( 'div', null, "🐈🐕🐇🐑").

image

@mourner mourner added bug and removed question labels Jan 8, 2020
@kzc
Copy link
Contributor

kzc commented Apr 29, 2020

Report this bug to https://github.com/acornjs/acorn-jsx.
It's emitting only the lower half of the UTF-16 surrogate pair.

As a workaround you can patch your local copy of acorn-jsx with:

--- a/node_modules/acorn-jsx/index.js
+++ b/node_modules/acorn-jsx/index.js
@@ -210,11 +210,11 @@
             if (str[1] === 'x') {
               str = str.substr(2);
               if (hexNumber.test(str))
-                entity = String.fromCharCode(parseInt(str, 16));
+                entity = String.fromCodePoint(parseInt(str, 16));
             } else {
               str = str.substr(1);
               if (decimalNumber.test(str))
-                entity = String.fromCharCode(parseInt(str, 10));
+                entity = String.fromCodePoint(parseInt(str, 10));
             }
           } else {
             entity = XHTMLEntities[str];

Bublé 0.20.0 without acorn-jsx patch:

$ echo '<div>&#65; &#x42; &#x1F415; &#128007; </div>;' | bin/buble
React.createElement( 'div', null, "A B   " );

Bublé 0.20.0 with acorn-jsx patch:

echo '<div>&#65; &#x42; &#x1F415; &#128007; </div>;' | bin/buble
React.createElement( 'div', null, "A B 🐕 🐇 " );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants