ソースを参照

Fixing issues rendering repeat errors coming from the rendering of an error page (like a missing helper).
Test added. Fixes #1671

mark_story 15 年 前
コミット
b31f25fb8b

+ 13 - 1
lib/Cake/Error/ExceptionRenderer.php

@@ -184,7 +184,7 @@ class ExceptionRenderer {
 			$this->controller->set($error->getAttributes());
 			$this->_outputMessage($this->template);
 		} catch (Exception $e) {
-			$this->_outputMessage('error500');
+			$this->_outputMessageSafe('error500');
 		}
 	}
 
@@ -235,4 +235,16 @@ class ExceptionRenderer {
 		$this->controller->afterFilter();
 		$this->controller->response->send();
 	}
+
+/**
+ * A safer way to render error messages, replaces all helpers, with basics
+ * and doesn't call component methods.
+ *
+ * @param string $template The template to render
+ */
+	protected function _outputMessageSafe($template) {
+		$this->controller->helpers = array('Form', 'Html', 'Session');
+		$this->controller->render($template);
+		$this->controller->response->send();
+	}
 }

+ 28 - 0
lib/Cake/tests/Case/Error/ExceptionRendererTest.php

@@ -609,4 +609,32 @@ class ExceptionRendererTest extends CakeTestCase {
 			$this->assertPattern($pattern, $result);
 		}
 	}
+
+/**
+ * Test exceptions being raised when helpers are missing.
+ *
+ * @return void
+ */
+	function testMissingRenderSafe() {
+		$exception = new MissingHelperFileException(array('class' => 'Fail'));
+		$ExceptionRenderer = new ExceptionRenderer($exception);
+
+		$ExceptionRenderer->controller = $this->getMock('Controller');
+		$ExceptionRenderer->controller->helpers = array('Fail', 'Boom');
+		$ExceptionRenderer->controller->request = $this->getMock('CakeRequest');
+		$ExceptionRenderer->controller->expects($this->at(2))
+			->method('render')
+			->with('missingHelperFile')
+			->will($this->throwException($exception));
+
+		$ExceptionRenderer->controller->expects($this->at(3))
+			->method('render')
+			->with('error500')
+			->will($this->returnValue(true));
+
+		$ExceptionRenderer->controller->response = $this->getMock('CakeResponse');
+		$ExceptionRenderer->render();
+		sort($ExceptionRenderer->controller->helpers);
+		$this->assertEquals(array('Form', 'Html', 'Session'), $ExceptionRenderer->controller->helpers);
+	}
 }