diff --git a/strbuf_helpers.c b/strbuf_helpers.c index 3e2373c7..0fa7f00f 100644 --- a/strbuf_helpers.c +++ b/strbuf_helpers.c @@ -715,7 +715,10 @@ static void _json_char(strbuf sb, uint32_t c) strbuf_puts(sb, "\\r"); else if (c == '\t') strbuf_puts(sb, "\\t"); - else if (c>0x7f || iscntrl(c)) + else if (c>=0x10000){ + c-=0x10000; + strbuf_sprintf(sb, "\\u%04X\\u%04X", 0xD800 + ((c>>10) & 0x3FF), 0xDC00 + (c & 0x3FF)); + }else if (c>0x7f || iscntrl(c)) strbuf_sprintf(sb, "\\u%04X", c); else strbuf_putc(sb, c); diff --git a/tests/meshmsrestful b/tests/meshmsrestful index 02f37b45..0a4287ef 100755 --- a/tests/meshmsrestful +++ b/tests/meshmsrestful @@ -776,4 +776,34 @@ test_sendFlood() { tfw_cat http.headers conversationlist.json } +doc_unicode="Send and receive unicode emoticons" +setup_unicode() { + IDENTITY_COUNT=2 + setup +} +test_unicode() { + SMILEY1=`echo -e "\xf0\x9f\x98\x80\x0a"` + SMILEY2=`echo -e "\xf0\x9f\x98\x90\x0a"` + executeOk_servald meshms send message $SIDA1 $SIDA2 "$SMILEY1" + executeOk curl \ + --silent --fail --show-error \ + --output sendmessage.json \ + --basic --user harry:potter \ + --form "message=$SMILEY2;type=text/plain;charset=utf-8" \ + "http://$addr_localhost:$PORTA/restful/meshms/$SIDA2/$SIDA1/sendmessage" + executeOk curl \ + --silent --fail --show-error \ + --output messagelist.json \ + --dump-header http.headers \ + --basic --user harry:potter \ + "http://$addr_localhost:$PORTA/restful/meshms/$SIDA1/$SIDA2/messagelist.json" + tfw_cat messagelist.json + assertGrep --matches=1 messagelist.json '\\uD83D\\uDE10' + assertGrep --matches=1 messagelist.json '\\uD83D\\uDE00' + executeOk_servald meshms list messages $SIDA1 $SIDA2 + tfw_cat --stdout + assertStdoutGrep --matches=1 "$SMILEY1" + assertStdoutGrep --matches=1 "$SMILEY2" +} + runTests "$@"