Browse Source

Merge pull request #1526 from TheShiftExchange/blade_e

Automatically apply entities to output using Blade
Taylor Otwell 12 years ago
parent
commit
6a69979376
2 changed files with 6 additions and 0 deletions
  1. 2 0
      laravel/blade.php
  2. 4 0
      laravel/tests/cases/blade.test.php

+ 2 - 0
laravel/blade.php

@@ -197,6 +197,8 @@ class Blade {
 	 */
 	protected static function compile_echos($value)
 	{
+		$value = preg_replace('/\{\{\{(.+?)\}\}\}/', '<?php echo HTML::entities($1); ?>', $value);
+
 		return preg_replace('/\{\{(.+?)\}\}/', '<?php echo $1; ?>', $value);
 	}
 

+ 4 - 0
laravel/tests/cases/blade.test.php

@@ -13,9 +13,13 @@ class BladeTest extends PHPUnit_Framework_TestCase {
 	{
 		$blade1 = '{{$a}}';
 		$blade2 = '{{e($a)}}';
+		$blade3 = '{{{$a}}}';
+		$blade4 = '{{{e($a)}}}';
 
 		$this->assertEquals('<?php echo $a; ?>', Blade::compile_string($blade1));
 		$this->assertEquals('<?php echo e($a); ?>', Blade::compile_string($blade2));
+		$this->assertEquals('<?php echo HTML::entities($a); ?>', Blade::compile_string($blade3));
+		$this->assertEquals('<?php echo HTML::entities(e($a)); ?>', Blade::compile_string($blade4));
 	}
 
 	/**