Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Allow escaping of Blade echos using @ sign.
- Loading branch information
|
@@ -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__); |
|
|