diff --git a/lib/Cake/Network/Http/Response.php b/lib/Cake/Network/Http/Response.php index f679157d164..ca0a472aea6 100644 --- a/lib/Cake/Network/Http/Response.php +++ b/lib/Cake/Network/Http/Response.php @@ -325,12 +325,12 @@ protected function _getJson() { * @return null|SimpleXML */ protected function _getXml() { - try { - $data = new \SimpleXMLElement($this->_body); - } catch (Exception $e) { - return null; + $restore = libxml_use_internal_errors(); + $data = simplexml_load_string($this->_body); + if ($data) { + return $data; } - return $data; + return null; } /** diff --git a/lib/Cake/Test/TestCase/Network/Http/ResponseTest.php b/lib/Cake/Test/TestCase/Network/Http/ResponseTest.php index 933dc325c59..44d598eebd1 100644 --- a/lib/Cake/Test/TestCase/Network/Http/ResponseTest.php +++ b/lib/Cake/Test/TestCase/Network/Http/ResponseTest.php @@ -85,6 +85,10 @@ public function testBodyJson() { $response = new Response([], $encoded); $this->assertTrue(isset($response->json)); $this->assertEquals($data['property'], $response->json['property']); + + $data = ''; + $response = new Response([], $data); + $this->assertFalse(isset($response->json)); } /** @@ -102,6 +106,10 @@ public function testBodyXml() { $response = new Response([], $data); $this->assertTrue(isset($response->xml)); $this->assertEquals('Test', (string)$response->xml->test); + + $data = ''; + $response = new Response([], $data); + $this->assertFalse(isset($response->xml)); } /**