0012180: fix broken xml input (#2)
authorPaul Mehrer <p.mehrer@metaways.de>
Fri, 9 Sep 2016 12:10:03 +0000 (14:10 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Sun, 11 Sep 2016 15:24:33 +0000 (17:24 +0200)
CalDav - Improved invalid character handling in XML

only filter chars if error occurs.

Change-Id: Id9ff4e92b143a80fbfa72bf7f47b952e45013dfa
Reviewed-on: http://gerrit.tine20.com/customers/3555
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Import/CalDav/Client.php

index a56de2f..4c210c9 100644 (file)
@@ -297,7 +297,27 @@ class Tinebase_Import_CalDav_Client extends \Sabre\DAV\Client
      */
     public function parseMultiStatus($body)
     {
-        // remove possible broken chars here to avoid simplexml_load_string errors
-        return parent::parseMultiStatus(Tinebase_Helper::removeIllegalXMLChars($body));
+        $oldSetting = libxml_use_internal_errors(true);
+
+        try {
+            $result = parent::parseMultiStatus($body);
+
+            if (count($xmlErrors = libxml_get_errors()) > 0) {
+                if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__
+                    . ' XML errors occured: ' . print_r($xmlErrors, true));
+            }
+            libxml_clear_errors();
+            libxml_use_internal_errors($oldSetting);
+
+        } catch(InvalidArgumentException $e) {
+            libxml_clear_errors();
+            libxml_use_internal_errors($oldSetting);
+
+            // remove possible broken chars here to avoid simplexml_load_string errors
+            // this line may throw an Exception again! thats why the libxml_* functions are called in try and catch!
+            $result = parent::parseMultiStatus(Tinebase_Helper::removeIllegalXMLChars($body));
+        }
+
+        return $result;
     }
 }