Permalink
Browse files

Merge branch 'master' of https://github.com/webbie/framework into bla…

…de-default
  • Loading branch information...
taylorotwell committed Nov 1, 2013
2 parents 37fa9a1 + 5e1d5a7 commit 10f5bfae60a799b1f7862cb923e7cf2ecd086816
Showing with 66 additions and 1 deletion.
  1. +8 −1 src/Illuminate/View/Compilers/BladeCompiler.php
  2. +58 −0 tests/View/ViewBladeCompilerTest.php
@@ -193,6 +193,7 @@ protected function compileRegularEchos($value)
$callback = function($matches)
{
$matches[2] = preg_replace('/^(?!"|\')(.+?)(?:\s*\|\|\s*|\s+or\s+)(.+?)$/s', 'isset($1) ? $1 : $2', $matches[2]);
return $matches[1] ? substr($matches[0], 1) : '<?php echo '.$matches[2].'; ?>';
};
@@ -209,7 +210,13 @@ protected function compileEscapedEchos($value)
{
$pattern = sprintf('/%s\s*(.+?)\s*%s/s', $this->escapedTags[0], $this->escapedTags[1]);
return preg_replace($pattern, '<?php echo e($1); ?>', $value);
$callback = function($matches)
{
$matches[1] = preg_replace('/^(?!"|\')(.+?)(?:\s*\|\|\s*|\s+or\s+)(.+?)$/s', 'isset($1) ? $1 : $2', $matches[1]);
return '<?php echo e('.$matches[1].'); ?>';
};
return preg_replace_callback($pattern, $callback, $value);
}
/**
@@ -71,6 +71,64 @@ public function testEchosAreCompiled()
$this->assertEquals('<?php echo $name; ?>', $compiler->compileString('{{
$name
}}'));
$this->assertEquals('<?php echo isset($name) ? $name : "foo"; ?>', $compiler->compileString('{{ $name || "foo" }}'));
$this->assertEquals('<?php echo isset($name) ? $name : "foo"; ?>', $compiler->compileString('{{ $name||"foo" }}'));
$this->assertEquals('<?php echo isset($name) ? $name : "foo"; ?>', $compiler->compileString('{{$name||"foo"}}'));
$this->assertEquals('<?php echo isset($name) ? $name : "foo"; ?>', $compiler->compileString('{{
$name||"foo"
}}'));
$this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>', $compiler->compileString('{{ $name || \'foo\' }}'));
$this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>', $compiler->compileString('{{ $name||\'foo\' }}'));
$this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>', $compiler->compileString('{{$name||\'foo\'}}'));
$this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>', $compiler->compileString('{{
$name||\'foo\'
}}'));
$this->assertEquals('<?php echo isset($age) ? $age : 90; ?>', $compiler->compileString('{{ $age || 90 }}'));
$this->assertEquals('<?php echo isset($age) ? $age : 90; ?>', $compiler->compileString('{{ $age||90 }}'));
$this->assertEquals('<?php echo isset($age) ? $age : 90; ?>', $compiler->compileString('{{$age||90}}'));
$this->assertEquals('<?php echo isset($age) ? $age : 90; ?>', $compiler->compileString('{{
$age||90
}}'));
$this->assertEquals('<?php echo "Hello world || foo"; ?>', $compiler->compileString('{{ "Hello world || foo" }}'));
$this->assertEquals('<?php echo "Hello world||foo"; ?>', $compiler->compileString('{{ "Hello world||foo" }}'));
$this->assertEquals('<?php echo "Hello world||foo"; ?>', $compiler->compileString('{{"Hello world||foo"}}'));
$this->assertEquals('<?php echo "Hello world||foo"; ?>', $compiler->compileString('{{
"Hello world||foo"
}}'));
$this->assertEquals('<?php echo isset($name) ? $name : "foo"; ?>', $compiler->compileString('{{ $name or "foo" }}'));
$this->assertEquals('<?php echo isset($name) ? $name : "foo"; ?>', $compiler->compileString('{{$name or "foo"}}'));
$this->assertEquals('<?php echo isset($name) ? $name : "foo"; ?>', $compiler->compileString('{{
$name or "foo"
}}'));
$this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>', $compiler->compileString('{{ $name or \'foo\' }}'));
$this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>', $compiler->compileString('{{$name or \'foo\'}}'));
$this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>', $compiler->compileString('{{
$name or \'foo\'
}}'));
$this->assertEquals('<?php echo isset($age) ? $age : 90; ?>', $compiler->compileString('{{ $age or 90 }}'));
$this->assertEquals('<?php echo isset($age) ? $age : 90; ?>', $compiler->compileString('{{$age or 90}}'));
$this->assertEquals('<?php echo isset($age) ? $age : 90; ?>', $compiler->compileString('{{
$age or 90
}}'));
$this->assertEquals('<?php echo "Hello world or foo"; ?>', $compiler->compileString('{{ "Hello world or foo" }}'));
$this->assertEquals('<?php echo "Hello world or foo"; ?>', $compiler->compileString('{{"Hello world or foo"}}'));
$this->assertEquals('<?php echo "Hello world or foo"; ?>', $compiler->compileString('{{
"Hello world or foo"
}}'));
$this->assertEquals('<?php echo \'Hello world or foo\'; ?>', $compiler->compileString('{{ \'Hello world or foo\' }}'));
$this->assertEquals('<?php echo \'Hello world or foo\'; ?>', $compiler->compileString('{{\'Hello world or foo\'}}'));
$this->assertEquals('<?php echo \'Hello world or foo\'; ?>', $compiler->compileString('{{
\'Hello world or foo\'
}}'));
}

0 comments on commit 10f5bfa

Please sign in to comment.