sw/qa/extras/ooxmlexport/data/tdf151912.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx   |    5 +++
 writerfilter/source/dmapper/SdtHelper.cxx    |   36 ++++++++++++++++++++-------
 3 files changed, 32 insertions(+), 9 deletions(-)

New commits:
commit b15c82e02c0a97d3523b6e46cb4ba4c958ea38d0
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Tue Nov 8 14:55:40 2022 +0300
Commit:     Vasily Melenchuk <vasily.melenc...@cib.de>
CommitDate: Mon Nov 14 09:20:42 2022 +0100

    tdf#151912: sw: suppress exceptions during SDT evluation
    
    Failure in XPath processing during retrieving fresh value from
    data source is not a critical problem and should not cancel
    document loading.
    
    Just put warning in log and continue to eval further.
    
    Change-Id: I76ecf0e0e227f46a270db3e77d86c19f7e9ad21a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142428
    Tested-by: Jenkins
    Reviewed-by: Vasily Melenchuk <vasily.melenc...@cib.de>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf151912.docx 
b/sw/qa/extras/ooxmlexport/data/tdf151912.docx
new file mode 100644
index 000000000000..65e8d5a93f87
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf151912.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 1ce78f262eef..6f76391d75dd 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -101,6 +101,11 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf149551_mongolianVert)
     assertXPath(pXmlDoc, "//wps:bodyPr", "vert", "mongolianVert");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf151912, "tdf151912.docx")
+{
+    // For now just ensure roundtrip is successful
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf147724, "tdf147724.docx")
 {
     const auto& pLayout = parseLayoutDump();
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx 
b/writerfilter/source/dmapper/SdtHelper.cxx
index d8f48ef7ffe2..cf86a629219b 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -28,6 +28,7 @@
 #include <com/sun/star/document/XOOXMLDocumentPropertiesImporter.hpp>
 #include <ooxml/OOXMLDocument.hxx>
 #include <com/sun/star/xml/xpath/XPathAPI.hpp>
+#include <com/sun/star/xml/xpath/XPathException.hpp>
 #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
 
 namespace writerfilter::dmapper
@@ -225,25 +226,42 @@ std::optional<OUString> 
SdtHelper::getValueFromDataBinding()
     const auto& aSourceIt = m_xPropertiesXMLs.find(m_sDataBindingStoreItemID);
     if (aSourceIt != m_xPropertiesXMLs.end())
     {
-        uno::Reference<XXPathObject> xResult
-            = xXpathAPI->eval(aSourceIt->second, m_sDataBindingXPath);
+        try
+        {
+            uno::Reference<XXPathObject> xResult
+                = xXpathAPI->eval(aSourceIt->second, m_sDataBindingXPath);
 
-        if (xResult.is() && xResult->getNodeList() && 
xResult->getNodeList()->getLength()
-            && xResult->getString().getLength())
+            if (xResult.is() && xResult->getNodeList() && 
xResult->getNodeList()->getLength()
+                && xResult->getString().getLength())
+            {
+                return xResult->getString();
+            }
+        }
+        catch (const XPathException& e)
         {
-            return xResult->getString();
+            // XPath failed? Log and continue with next data document
+            SAL_WARN("writerfilter", "SdtHelper::failed running XPath: " << 
e.Message);
         }
     }
 
     // Nothing found? Try to iterate storages and eval xpath
     for (const auto& aSource : m_xPropertiesXMLs)
     {
-        uno::Reference<XXPathObject> xResult = xXpathAPI->eval(aSource.second, 
m_sDataBindingXPath);
+        try
+        {
+            uno::Reference<XXPathObject> xResult
+                = xXpathAPI->eval(aSource.second, m_sDataBindingXPath);
 
-        if (xResult.is() && xResult->getNodeList() && 
xResult->getNodeList()->getLength()
-            && xResult->getString().getLength())
+            if (xResult.is() && xResult->getNodeList() && 
xResult->getNodeList()->getLength()
+                && xResult->getString().getLength())
+            {
+                return xResult->getString();
+            }
+        }
+        catch (const XPathException& e)
         {
-            return xResult->getString();
+            // XPath failed? Log and continue with next data document
+            SAL_WARN("writerfilter", "SdtHelper::failed running XPath: " << 
e.Message);
         }
     }
 

Reply via email to