Permalink
Browse files

Allow escaping of Blade echos using @ sign.

  • Loading branch information...
taylorotwell committed Oct 16, 2013
1 parent ee25cd0 commit cb93bf3df8d25c04939462f81b75ddb9e4e6faa0
Showing with 21 additions and 2 deletions.
  1. +7 −2 src/Illuminate/View/Compilers/BladeCompiler.php
  2. +14 −0 tests/View/ViewBladeCompilerTest.php
@@ -190,9 +190,14 @@ protected function compileEchos($value)
*/
protected function compileRegularEchos($value)
{
$pattern = sprintf('/%s\s*(.+?)\s*%s/s', $this->contentTags[0], $this->contentTags[1]);
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s/s', $this->contentTags[0], $this->contentTags[1]);
return preg_replace($pattern, '<?php echo $1; ?>', $value);
$callback = function($matches)
{
return $matches[1] ? substr($matches[0], 1) : '<?php echo '.$matches[2].'; ?>';
};
return preg_replace_callback($pattern, $callback, $value);
}
/**
@@ -74,6 +74,20 @@ public function testEchosAreCompiled()
}
public function testEscapedWithAtEchosAreCompiled()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
$this->assertEquals('{{$name}}', $compiler->compileString('@{{$name}}'));
$this->assertEquals('{{ $name }}', $compiler->compileString('@{{ $name }}'));
$this->assertEquals('{{
$name
}}',
$compiler->compileString('@{{
$name
}}'));
}
public function testReversedEchosAreCompiled()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);

0 comments on commit cb93bf3

Please sign in to comment.