From: Art Cancro Date: Fri, 3 Nov 2023 04:13:46 +0000 (-0900) Subject: json.c: encode JSON strings the correct way (RFC 7159 section 7). X-Git-Tag: v997~102 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=1158e6626314814cd66c74880738168bba8b32bc;p=citadel.git json.c: encode JSON strings the correct way (RFC 7159 section 7). The previous code used the JavaScript encoder from the stringbuf library, which is *not* the same encoding. Now it doesn't make the browser's parser barf when it encounters a control character. --- diff --git a/libcitadel/lib/json.c b/libcitadel/lib/json.c index d664700fa..277bfe0cb 100644 --- a/libcitadel/lib/json.c +++ b/libcitadel/lib/json.c @@ -1,7 +1,7 @@ // // JSON data type and serializer for Citadel // -// Copyright (c) 1987-2018 by the citadel.org team +// Copyright (c) 1987-2023 by the citadel.org team // // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. @@ -197,7 +197,32 @@ void SerializeJson(StrBuf *Target, JsonValue *Val, int FreeVal) { switch (Val->Type) { case JSON_STRING: StrBufAppendBufPlain(Target, HKEY("\""), 0); - StrECMAEscAppend(Target, Val->Value, NULL); + int i; + char *plain = (char *)ChrPtr(Val->Value); + if (!IsEmptyStr(plain)) { + int len = strlen(plain); + for (i=0; i