sfx2/source/view/lokhelper.cxx |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

New commits:
commit d4aaf8f699233d4e63a9293d0ac7ffbe2cface14
Author:     mert <mert.tu...@collabora.com>
AuthorDate: Mon Feb 22 11:17:27 2021 +0300
Commit:     Mert Tumer <mert.tu...@collabora.com>
CommitDate: Wed Feb 24 08:39:37 2021 +0100

    Fix non-valid json generation on NotifyOtherViews
    
    Change-Id: I82aa0aefcd1de14b4c1bb2bbe3f087b60d691beb
    Signed-off-by: mert <mert.tu...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111299
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 3c1ecd207159..9208c6e35476 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -303,7 +303,11 @@ void SfxLokHelper::setDeviceFormFactor(const OUString& 
rDeviceFormFactor)
         g_deviceFormFactor = LOKDeviceFormFactor::UNKNOWN;
 }
 
-static OString lcl_escapeQuotes(const OString &rStr)
+/*
+* Used for putting a whole JSON string into a string value
+* e.g { key: "{JSON}" }
+*/
+static OString lcl_sanitizeJSONAsValue(const OString &rStr)
 {
     if (rStr.getLength() < 1)
         return rStr;
@@ -313,7 +317,9 @@ static OString lcl_escapeQuotes(const OString &rStr)
     {
         if (rStr[i] == '"' || rStr[i] == '\\')
             aBuf.append('\\');
-        aBuf.append(rStr[i]);
+
+        if (rStr[i] != '\n')
+            aBuf.append(rStr[i]);
     }
     return aBuf.makeStringAndClear();
 }
@@ -336,7 +342,7 @@ static inline OString lcl_generateJSON(const SfxViewShell* 
pView, const OString&
     assert(pView != nullptr && "pView must be valid");
     return OStringLiteral("{ \"viewId\": \"") + 
OString::number(SfxLokHelper::getView(pView))
            + "\", \"part\": \"" + OString::number(pView->getPart()) + "\", \"" 
+ rKey + "\": \""
-           + lcl_escapeQuotes(rPayload) + "\" }";
+           + lcl_sanitizeJSONAsValue(rPayload) + "\" }";
 }
 
 void SfxLokHelper::notifyOtherView(const SfxViewShell* pThisView, SfxViewShell 
const* pOtherView,
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to