From 41e0c524f245c66e0ad077d084587e263f550572 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 26 May 2013 22:11:13 -0400 Subject: [PATCH 1/3] Only try to use CakeErrorController if AppController exists. This fixes missing error pages when there are parse errors in AppController. Fixes #3850 --- lib/Cake/Error/ExceptionRenderer.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 069ed1860..9eb5b0111 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -151,12 +151,14 @@ class ExceptionRenderer { $response->header($exception->responseHeader()); } - try { - $controller = new CakeErrorController($request, $response); - $controller->startupProcess(); - } catch (Exception $e) { - if (!empty($controller) && $controller->Components->enabled('RequestHandler')) { - $controller->RequestHandler->startup($controller); + if (class_exists('AppController')) { + try { + $controller = new CakeErrorController($request, $response); + $controller->startupProcess(); + } catch (Exception $e) { + if (!empty($controller) && $controller->Components->enabled('RequestHandler')) { + $controller->RequestHandler->startup($controller); + } } } if (empty($controller)) { From 7334643b55f2b28d26876db733ab153e3942deb5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 27 May 2013 13:22:14 -0400 Subject: [PATCH 2/3] Fix issues with getting Xml as SimpleXmlElement and invalid Xml. Fixes #3855 --- lib/Cake/Test/Case/Utility/XmlTest.php | 13 ++++++++++++- lib/Cake/Utility/Xml.php | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/XmlTest.php b/lib/Cake/Test/Case/Utility/XmlTest.php index b28a4efc0..820202c17 100644 --- a/lib/Cake/Test/Case/Utility/XmlTest.php +++ b/lib/Cake/Test/Case/Utility/XmlTest.php @@ -187,12 +187,23 @@ class XmlTest extends CakeTestCase { * * @dataProvider invalidDataProvider * @expectedException XmlException - * return void + * @return void */ public function testBuildInvalidData($value) { Xml::build($value); } +/** + * Test that building SimpleXmlElement with invalid XML causes the right exception. + * + * @expectedException XmlException + * @return void + */ + public function testBuildInvalidDataSimpleXml() { + $input = ' 'simplexml')); + } + /** * test build with a single empty tag * diff --git a/lib/Cake/Utility/Xml.php b/lib/Cake/Utility/Xml.php index f446798a3..19ea1725e 100644 --- a/lib/Cake/Utility/Xml.php +++ b/lib/Cake/Utility/Xml.php @@ -131,16 +131,23 @@ class Xml { if ($hasDisable && !$options['loadEntities']) { libxml_disable_entity_loader(true); } - if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') { - $xml = new SimpleXMLElement($input, LIBXML_NOCDATA); - } else { - $xml = new DOMDocument(); - $xml->loadXML($input); + try { + if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') { + $xml = new SimpleXMLElement($input, LIBXML_NOCDATA); + } else { + $xml = new DOMDocument(); + $xml->loadXML($input); + } + } catch (Exception $e) { + $xml = null; } if ($hasDisable && !$options['loadEntities']) { libxml_disable_entity_loader(false); } libxml_use_internal_errors($internalErrors); + if ($xml === null) { + throw new XmlException(__d('cake_dev', 'Xml cannot be read.')); + } return $xml; } From 49aded5399e52ae0911b130e09522770cc29d81b Mon Sep 17 00:00:00 2001 From: Ceeram Date: Tue, 28 May 2013 18:37:10 +0200 Subject: [PATCH 3/3] fix coding standard error --- lib/Cake/Utility/Xml.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Utility/Xml.php b/lib/Cake/Utility/Xml.php index 19ea1725e..f58ccce49 100644 --- a/lib/Cake/Utility/Xml.php +++ b/lib/Cake/Utility/Xml.php @@ -124,6 +124,7 @@ class Xml { * @param string $input The input to load. * @param array $options The options to use. See Xml::build() * @return SimpleXmlElement|DOMDocument + * @throws XmlException */ protected static function _loadXml($input, $options) { $hasDisable = function_exists('libxml_disable_entity_loader');