lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx |   19 
+++++++---
 1 file changed, 15 insertions(+), 4 deletions(-)

New commits:
commit 13873b70b947d0ef6a809606424e7b837d8f6625
Author:     Gökay Şatır <gokaysa...@collabora.com>
AuthorDate: Fri Oct 13 15:19:22 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Oct 16 15:06:57 2023 +0200

    Language tool response fix.
    
    Don't crash if "matches" key is not present in JSON data.
    Use a warning since "matches" key is expected.
    
    Signed-off-by: Gökay Şatır <gokaysa...@collabora.com>
    Change-Id: I10a04a5b5d45541813c932f59f495409baed1f07
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158022
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx 
b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
index 1537e036f035..598fce4713bb 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
@@ -354,17 +354,28 @@ void 
LanguageToolGrammarChecker::parseProofreadingJSONResponse(ProofreadingResul
     boost::property_tree::ptree root;
     std::stringstream aStream(aJSONBody.data());
     boost::property_tree::read_json(aStream, root);
-    boost::property_tree::ptree& matches = root.get_child("matches");
-    size_t matchSize = matches.size();
+    boost::property_tree::ptree* matches;
+    size_t matchSize;
 
-    if (matchSize <= 0)
+    if (root.find("matches") == root.not_found())
     {
+        SAL_WARN("Language Services", "'matches' property doesn't exist in 
JSON object.");
         return;
     }
+    else
+    {
+        matches = &root.get_child("matches");
+
+        if (matches->size() <= 0)
+            return;
+        else
+            matchSize = matches->size();
+    }
+
     Sequence<SingleProofreadingError> aErrors(matchSize);
     auto pErrors = aErrors.getArray();
     size_t i = 0;
-    for (auto it1 = matches.begin(); it1 != matches.end(); it1++, i++)
+    for (auto it1 = matches->begin(); it1 != matches->end(); it1++, i++)
     {
         const boost::property_tree::ptree& match = it1->second;
         int offset = match.get<int>("offset");

Reply via email to