summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authormert <mert.tumer@collabora.com>2021-02-22 11:17:27 +0300
committerMert Tumer <mert.tumer@collabora.com>2021-02-24 08:39:37 +0100
commitd4aaf8f699233d4e63a9293d0ac7ffbe2cface14 (patch)
tree5d3406b7b290562aad089bfd5e544ce70c8ab1ac /sfx2
parent8c7a1b06e445f6e61b5127b6ba8a80fb3cfba454 (diff)
Fix non-valid json generation on NotifyOtherViews
Change-Id: I82aa0aefcd1de14b4c1bb2bbe3f087b60d691beb Signed-off-by: mert <mert.tumer@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111299 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/view/lokhelper.cxx12
1 files changed, 9 insertions, 3 deletions
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,