summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-06-28 12:30:40 +0100
committerMichael Meeks <michael.meeks@collabora.com>2019-07-20 11:09:45 +0100
commit7376f6cb28232cc47da656059cd947eacaebb539 (patch)
tree54cf797917d2b1f5096def782c6e6ea9df6225f7
parentb2d70ac18e4f61b8bc68f0b091653a3a2992e0ab (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.cxx17
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());
}