Browse Source

[ZF-6265] Zend Rest Result.php does not handle invalid XML properly - error handlers are ignored

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18973 44c647ce-9c0f-0410-b52a-842ac1e357ba
yoshida@zend.co.jp 16 years ago
parent
commit
cff112374a
1 changed files with 18 additions and 7 deletions
  1. 18 7
      library/Zend/Rest/Client/Result.php

+ 18 - 7
library/Zend/Rest/Client/Result.php

@@ -34,6 +34,12 @@ class Zend_Rest_Client_Result implements IteratorAggregate {
     protected $_sxml;
 
     /**
+     * error information
+     * @var string
+     */
+    protected $_errstr;
+
+    /**
      * Constructor
      *
      * @param string $data XML Result
@@ -43,10 +49,16 @@ class Zend_Rest_Client_Result implements IteratorAggregate {
     {
         set_error_handler(array($this, 'handleXmlErrors'));
         $this->_sxml = simplexml_load_string($data);
+        restore_error_handler();
         if($this->_sxml === false) {
-            $this->handleXmlErrors(0, "An error occured while parsing the REST response with simplexml.");
-        } else {
-            restore_error_handler();
+            if ($this->_errstr === null) {
+                $message = "An error occured while parsing the REST response with simplexml.";
+            } else {
+                $message = "REST Response Error: " . $this->_errstr;
+                $this->_errstr = null;
+            }
+            require_once "Zend/Rest/Client/Result/Exception.php";
+            throw new Zend_Rest_Client_Result_Exception($message);
         }
     }
 
@@ -58,13 +70,12 @@ class Zend_Rest_Client_Result implements IteratorAggregate {
      * @param string $errfile
      * @param string $errline
      * @param array  $errcontext
-     * @throws Zend_Result_Client_Result_Exception
+     * @return true
      */
     public function handleXmlErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
     {
-        restore_error_handler();
-        require_once "Zend/Rest/Client/Result/Exception.php";
-        throw new Zend_Rest_Client_Result_Exception("REST Response Error: ".$errstr);
+        $this->_errstr = $errstr;
+        return true;
     }
 
     /**