@@ -901,7 +901,7 @@ public function displayError($code,$message,$file,$line)
901901 if (YII_DEBUG )
902902 {
903903 echo "<h1>PHP Error [ $ code]</h1> \n" ;
904- echo "<p> $ message ( $ file: $ line)</p> \n" ;
904+ echo "<p> " . nl2br ( $ this -> htmlEncodeInternal ( $ message)). " ( " . $ this -> htmlEncodeInternal ( $ file). " : $ line)</p> \n" ;
905905 echo '<pre> ' ;
906906
907907 $ trace =debug_backtrace ();
@@ -927,7 +927,7 @@ public function displayError($code,$message,$file,$line)
927927 else
928928 {
929929 echo "<h1>PHP Error [ $ code]</h1> \n" ;
930- echo "<p> $ message</p> \n" ;
930+ echo "<p> " . nl2br ( $ this -> htmlEncodeInternal ( $ message)). " </p> \n" ;
931931 }
932932 }
933933
@@ -942,16 +942,26 @@ public function displayException($exception)
942942 if (YII_DEBUG )
943943 {
944944 echo '<h1> ' .get_class ($ exception )."</h1> \n" ;
945- echo '<p> ' .$ exception ->getMessage ().' ( ' .$ exception ->getFile ().': ' .$ exception ->getLine ().')</p> ' ;
946- echo '<pre> ' .$ exception ->getTraceAsString ().'</pre> ' ;
945+ echo '<p> ' .nl2br ( $ this -> htmlEncodeInternal ( $ exception ->getMessage ())) .' ( ' .$ this -> htmlEncodeInternal ( $ exception ->getFile () ).': ' .$ exception ->getLine ().')</p> ' ;
946+ echo '<pre> ' .$ this -> htmlEncodeInternal ( $ exception ->getTraceAsString () ).'</pre> ' ;
947947 }
948948 else
949949 {
950950 echo '<h1> ' .get_class ($ exception )."</h1> \n" ;
951- echo '<p> ' .$ exception ->getMessage ().'</p> ' ;
951+ echo '<p> ' .nl2br ( $ this -> htmlEncodeInternal ( $ exception ->getMessage ()) ).'</p> ' ;
952952 }
953953 }
954954
955+ /**
956+ * Encode html without a dependency on CHtml::encode(). This method is internally used by displayError/displayException.
957+ * @param string $string
958+ * @return string
959+ */
960+ private function htmlEncodeInternal ($ string )
961+ {
962+ return htmlspecialchars ($ string , ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_HTML5 , 'UTF-8 ' );
963+ }
964+
955965 /**
956966 * Initializes the error handlers.
957967 */
0 commit comments