diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-06-28 12:30:40 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-08-02 11:41:49 -0400 |
commit | 05683f3ade1ed623847df5204338f440981239c7 (patch) | |
tree | 8cf2363750bd150b7b6f9896f6ec60fd800ce543 | |
parent | bd304791005f6006487941272dfac525509434ea (diff) |
lok: vital to quote nested JSON inserted into a json property.
Somehow this managed to work fine in most browsers, but when
the Kit/Poco tried to parse JSON to extract viewID it could explode.
Change-Id: I39d2ecc9ee95b7e6f67a23c8b15f9a1d01769ddc
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index a7828287205d..55b157ef6cb2 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -143,11 +143,26 @@ void SfxLokHelper::setViewLanguage(int nId, const OUString& rBcp47LanguageTag) } } +static OString lcl_escapeQuotes(const OString &rStr) +{ + if (rStr.getLength() < 1) + return rStr; + // FIXME: need an optimized 'escape' method for O[U]String. + OStringBuffer aBuf(rStr.getLength() + 8); + for (sal_Int32 i = 0; i < rStr.getLength(); ++i) + { + if (rStr[i] == '"' || rStr[i] == '\\') + aBuf.append('\\'); + aBuf.append(rStr[i]); + } + return aBuf.makeStringAndClear(); +} + void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* pOtherView, int nType, const OString& rKey, const OString& rPayload) { OString aPayload = OString("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView(pThisView)) + "\", \"part\": \"" + OString::number(pThisView->getPart()) + - "\", \"" + rKey + "\": \"" + rPayload + "\" }"; + "\", \"" + rKey + "\": \"" + lcl_escapeQuotes(rPayload) + "\" }"; pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr()); } |