diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index e90d6aa5b72c..5a306fed8b31 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -455,6 +455,25 @@ function e($value) } } +if(! function_exists('be')) { + /** + * Escape Blade-specific HTML entities in a string. + * + * @param \Illuminate\Support\Htmlable|string $value + * @return string + */ + function be($value) + { + if ($value instanceof Htmlable) { + return $value->toHtml(); + } + + $value = e($value, ENT_QUOTES, 'UTF-8', false); + $value = str_replace("@", "@", $value); + return $value; + } +} + if (! function_exists('ends_with')) { /** * Determine if a given string ends with a given substring. diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index bd8eca1e3d76..0909b8f584d0 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -68,7 +68,7 @@ class BladeCompiler extends Compiler implements CompilerInterface * * @var string */ - protected $echoFormat = 'e(%s)'; + protected $echoFormat = 'be(%s)'; /** * Array of footer lines to be added to template. @@ -331,7 +331,7 @@ protected function compileEscapedEchos($value) $callback = function ($matches) { $whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3]; - return $matches[1] ? $matches[0] : 'compileEchoDefaults($matches[2]).'); ?>'.$whitespace; + return $matches[1] ? $matches[0] : 'compileEchoDefaults($matches[2]).'); ?>'.$whitespace; }; return preg_replace_callback($pattern, $callback, $value); diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index 7164170cb4bc..8f87ca030c64 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -94,52 +94,52 @@ public function testEchosAreCompiled() !!}')); $this->assertEquals('', $compiler->compileString('{!! $name or \'foo\' !!}')); - $this->assertEquals('', $compiler->compileString('{{{$name}}}')); - $this->assertEquals('', $compiler->compileString('{{$name}}')); - $this->assertEquals('', $compiler->compileString('{{ $name }}')); - $this->assertEquals('', $compiler->compileString('{{ + $this->assertEquals('', $compiler->compileString('{{{$name}}}')); + $this->assertEquals('', $compiler->compileString('{{$name}}')); + $this->assertEquals('', $compiler->compileString('{{ $name }}')); + $this->assertEquals('', $compiler->compileString('{{ $name }}')); - $this->assertEquals("\n\n", $compiler->compileString("{{ \$name }}\n")); - $this->assertEquals("\r\n\r\n", $compiler->compileString("{{ \$name }}\r\n")); - $this->assertEquals("\n\n", $compiler->compileString("{{ \$name }}\n")); - $this->assertEquals("\r\n\r\n", $compiler->compileString("{{ \$name }}\r\n")); - - $this->assertEquals('', $compiler->compileString('{{ $name or "foo" }}')); - $this->assertEquals('name) ? $user->name : "foo"); ?>', $compiler->compileString('{{ $user->name or "foo" }}')); - $this->assertEquals('', $compiler->compileString('{{$name or "foo"}}')); - $this->assertEquals('', $compiler->compileString('{{ + $this->assertEquals("\n\n", $compiler->compileString("{{ \$name }}\n")); + $this->assertEquals("\r\n\r\n", $compiler->compileString("{{ \$name }}\r\n")); + $this->assertEquals("\n\n", $compiler->compileString("{{ \$name }}\n")); + $this->assertEquals("\r\n\r\n", $compiler->compileString("{{ \$name }}\r\n")); + + $this->assertEquals('', $compiler->compileString('{{ $name or "foo" }}')); + $this->assertEquals('name) ? $user->name : "foo"); ?>', $compiler->compileString('{{ $user->name or "foo" }}')); + $this->assertEquals('', $compiler->compileString('{{$name or "foo"}}')); + $this->assertEquals('', $compiler->compileString('{{ $name or "foo" }}')); - $this->assertEquals('', $compiler->compileString('{{ $name or \'foo\' }}')); - $this->assertEquals('', $compiler->compileString('{{$name or \'foo\'}}')); - $this->assertEquals('', $compiler->compileString('{{ + $this->assertEquals('', $compiler->compileString('{{ $name or \'foo\' }}')); + $this->assertEquals('', $compiler->compileString('{{$name or \'foo\'}}')); + $this->assertEquals('', $compiler->compileString('{{ $name or \'foo\' }}')); - $this->assertEquals('', $compiler->compileString('{{ $age or 90 }}')); - $this->assertEquals('', $compiler->compileString('{{$age or 90}}')); - $this->assertEquals('', $compiler->compileString('{{ + $this->assertEquals('', $compiler->compileString('{{ $age or 90 }}')); + $this->assertEquals('', $compiler->compileString('{{$age or 90}}')); + $this->assertEquals('', $compiler->compileString('{{ $age or 90 }}')); - $this->assertEquals('', $compiler->compileString('{{ "Hello world or foo" }}')); - $this->assertEquals('', $compiler->compileString('{{"Hello world or foo"}}')); - $this->assertEquals('', $compiler->compileString('{{$foo + $or + $baz}}')); - $this->assertEquals('', $compiler->compileString('{{ + $this->assertEquals('', $compiler->compileString('{{ "Hello world or foo" }}')); + $this->assertEquals('', $compiler->compileString('{{"Hello world or foo"}}')); + $this->assertEquals('', $compiler->compileString('{{$foo + $or + $baz}}')); + $this->assertEquals('', $compiler->compileString('{{ "Hello world or foo" }}')); - $this->assertEquals('', $compiler->compileString('{{ \'Hello world or foo\' }}')); - $this->assertEquals('', $compiler->compileString('{{\'Hello world or foo\'}}')); - $this->assertEquals('', $compiler->compileString('{{ + $this->assertEquals('', $compiler->compileString('{{ \'Hello world or foo\' }}')); + $this->assertEquals('', $compiler->compileString('{{\'Hello world or foo\'}}')); + $this->assertEquals('', $compiler->compileString('{{ \'Hello world or foo\' }}')); - $this->assertEquals('', $compiler->compileString('{{ myfunc(\'foo or bar\') }}')); - $this->assertEquals('', $compiler->compileString('{{ myfunc("foo or bar") }}')); - $this->assertEquals('', $compiler->compileString('{{ myfunc("$name or \'foo\'") }}')); + $this->assertEquals('', $compiler->compileString('{{ myfunc(\'foo or bar\') }}')); + $this->assertEquals('', $compiler->compileString('{{ myfunc("foo or bar") }}')); + $this->assertEquals('', $compiler->compileString('{{ myfunc("$name or \'foo\'") }}')); } public function testEscapedWithAtEchosAreCompiled() @@ -498,7 +498,7 @@ public function testCustomPhpCodeIsCorrectlyHandled() public function testMixingYieldAndEcho() { $compiler = new BladeCompiler($this->getFiles(), __DIR__); - $this->assertEquals('yieldContent(\'title\'); ?> - ', $compiler->compileString("@yield('title') - {{Config::get('site.title')}}")); + $this->assertEquals('yieldContent(\'title\'); ?> - ', $compiler->compileString("@yield('title') - {{Config::get('site.title')}}")); } public function testCustomExtensionsAreCompiled() @@ -543,7 +543,7 @@ public function testRawTagsCanBeSetToLegacyValues() $compiler = new BladeCompiler($this->getFiles(), __DIR__); $compiler->setEchoFormat('%s'); - $this->assertEquals('', $compiler->compileString('{{{ $name }}}')); + $this->assertEquals('', $compiler->compileString('{{{ $name }}}')); $this->assertEquals('', $compiler->compileString('{{ $name }}')); $this->assertEquals('', $compiler->compileString('{{ $name @@ -559,9 +559,9 @@ public function testExpressionsOnTheSameLine() public function testExpressionWithinHTML() { $compiler = new BladeCompiler($this->getFiles(), __DIR__); - $this->assertEquals('>', $compiler->compileString('')); - $this->assertEquals('>', $compiler->compileString('')); - $this->assertEquals(' get(\'foo\'); ?>>', $compiler->compileString('')); + $this->assertEquals('>', $compiler->compileString('')); + $this->assertEquals('>', $compiler->compileString('')); + $this->assertEquals(' get(\'foo\'); ?>>', $compiler->compileString('')); } protected function getFiles()