jsx
jsx copied to clipboard
Emoji Surrogate support
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"
)?
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
hi @talentdeficit, Is there an update on this issue ?
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\"}">>
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>>, [???]).