diff options
author | mert <mert.tumer@collabora.com> | 2021-02-22 11:17:27 +0300 |
---|---|---|
committer | Mert Tumer <mert.tumer@collabora.com> | 2021-03-03 08:42:09 +0100 |
commit | a434f5d2d4ff4991937b57e521782ad3594aa370 (patch) | |
tree | 5aa1162ef77540dbe3ab1720438090f137f157eb | |
parent | 63dd594d535b1272a29a3f4217212b6063a08af6 (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>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111515
Tested-by: Jenkins
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index cdd6030a7c8f..2a5ea882d92d 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -308,7 +308,11 @@ void SfxLokHelper::setDeviceFormFactor(std::u16string_view 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; @@ -318,7 +322,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(); } @@ -341,7 +347,7 @@ static inline OString lcl_generateJSON(const SfxViewShell* pView, std::string_vi 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, |