tools/source/misc/json_writer.cxx |    9 +++++++++
 1 file changed, 9 insertions(+)

New commits:
commit 5b4a36483719e3dbc87bde8df3f78f2c840be649
Author:     Szymon Kłos <[email protected]>
AuthorDate: Thu May 25 09:38:12 2023 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Thu May 25 10:50:41 2023 +0200

    jsdialog: encode properly control characters
    
    according to https://www.rfc-editor.org/rfc/rfc7159#section-7
    strings in JSON should contain control characters (0x00-0x1f)
    encoded as \uXXXX
    
    Signed-off-by: Szymon Kłos <[email protected]>
    Change-Id: I1f828f64e57328b5fa2dcf5853afe0d6ea643081
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152262
    Reviewed-by: Attila Szűcs <[email protected]>
    Tested-by: Attila Szűcs <[email protected]>

diff --git a/tools/source/misc/json_writer.cxx 
b/tools/source/misc/json_writer.cxx
index 5bc718608d6a..95210d7e7fa7 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -156,6 +156,15 @@ static char getEscapementChar(char ch)
 
 static bool writeEscapedSequence(sal_uInt32 ch, char*& pos)
 {
+    // control characters
+    if (ch <= 0x1f)
+    {
+        int written = sprintf(pos, "\\u%.4x", ch);
+        if (written > 0)
+            pos += written;
+        return true;
+    }
+
     switch (ch)
     {
         case '\b':

Reply via email to