mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-31 08:25:22 +00:00
Escape codepoints U+10000 to U+10FFFF in json output as surrogate pairs
This commit is contained in:
parent
fc943fdb19
commit
d1a1a41f08
@ -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);
|
||||
|
@ -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 "$@"
|
||||
|
Loading…
x
Reference in New Issue
Block a user