jsx icon indicating copy to clipboard operation
jsx copied to clipboard

Emoji Surrogate support

Open c-bik opened this issue 7 years ago • 4 comments

Hi, I am trying to encode maps with emoji surrogate pairs. But when I am attempting:

jsx:encode(#{emoji => <<"\uXXXX\uXXXX">>}).
% The result is
<<"{\"emoji\":\"\\uXXXX\\uXXXX\"}">>

In which way should I construct the map so that "\uXXXX are not escaped again (like "\\uXXXX")?

c-bik avatar Aug 01 '17 01:08 c-bik

you can use the dirty_strings option to not escape strings

this looks like maybe a bug in the string escaping however. i will need to take a closer look

talentdeficit avatar Aug 02 '17 02:08 talentdeficit

hi @talentdeficit, Is there an update on this issue ?

shamis avatar Jun 11 '18 15:06 shamis

jsx:encode(#{emoji => <<"\uXXXX\uXXXX">>}).

You are trying to do a strange/wrong thing. There can be no surrogates in utf-8 binaries. jsx works correctly.

Ɛ> jsx:encode(#{ <<"rabbit">> => <<"\x{1f407}"/utf8>> }, [uescape]).      
<<"{\"rabbit\":\"\\ud83d\\udc07\"}">>

llelf avatar Dec 24 '18 17:12 llelf

jsx:encode(#{emoji => <<"\uXXXX\uXXXX">>}).

You are trying to do a strange/wrong thing. There can be no surrogates in utf-8 binaries. jsx works correctly.

Agree!

Ɛ> jsx:encode(#{ <<"rabbit">> => <<"\x{1f407}"/utf8>> }, [uescape]).      
<<"{\"rabbit\":\"\\ud83d\\udc07\"}">>

@llelf is this symmetric? (no erl vm at hand atm to check). What I mean is : if the following is also true:

> > #{ <<"rabbit">> => <<"\x{1f407}"/utf8>> } = jsx:decode(<<"{\"rabbit\":\"\\ud83d\\udc07\"}"/utf8>>, [???]). 

c-bik avatar Jul 03 '20 15:07 c-bik