Prechádzať zdrojové kódy

Switched error handling to use libxml_use_internal_errors() - fixes ZF-7305

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18256 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 16 rokov pred
rodič
commit
ac7f34c1b8
1 zmenil súbory, kde vykonal 17 pridanie a 10 odobranie
  1. 17 10
      library/Zend/Feed.php

+ 17 - 10
library/Zend/Feed.php

@@ -191,26 +191,33 @@ class Zend_Feed
     public static function importString($string)
     {
         // Load the feed as an XML DOMDocument object
-        @ini_set('track_errors', 1);
+        $libxml_errflag = libxml_use_internal_errors(true);
         $doc = new DOMDocument;
-        $status = @$doc->loadXML($string);
-        @ini_restore('track_errors');
+        if (trim($string) == '') {
+            require_once 'Zend/Feed/Exception.php';
+            throw new Zend_Feed_Exception('Document/string being imported'
+            . ' is an Empty string or comes from an empty HTTP response');
+        }
+        $status = $doc->loadXML($string);
+        libxml_use_internal_errors($libxml_errflag);
+
 
         if (!$status) {
             // prevent the class to generate an undefined variable notice (ZF-2590)
-            if (!isset($php_errormsg)) {
-                if (function_exists('xdebug_is_enabled')) {
-                    $php_errormsg = '(error message not available, when XDebug is running)';
-                } else {
-                    $php_errormsg = '(error message not available)';
-                }
+            // Build error message
+            $error = libxml_get_last_error();
+            if ($error && $error->message) {
+                $errormsg = "DOMDocument cannot parse XML: {$error->message}";
+            } else {
+                $errormsg = "DOMDocument cannot parse XML";
             }
 
+
             /**
              * @see Zend_Feed_Exception
              */
             require_once 'Zend/Feed/Exception.php';
-            throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
+            throw new Zend_Feed_Exception($errormsg);
         }
 
         // Try to find the base feed element or a single <entry> of an Atom feed