From 3e6e1ef9cd000afb7da275d3a11a6bf83324c59d Mon Sep 17 00:00:00 2001 From: tjallingt Date: Thu, 31 May 2018 15:29:11 +0200 Subject: [PATCH 1/2] fixed bug where 0 as an argument to a custom blade conditional was ignored --- src/Illuminate/View/Compilers/BladeCompiler.php | 4 ++-- tests/View/Blade/BladeCustomTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index f53bf1fc013b..965fd7ba6427 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -396,13 +396,13 @@ public function if($name, callable $callback) $this->conditions[$name] = $callback; $this->directive($name, function ($expression) use ($name) { - return $expression + return $expression !== '' ? "" : ""; }); $this->directive('else'.$name, function ($expression) use ($name) { - return $expression + return $expression !== '' ? "" : ""; }); diff --git a/tests/View/Blade/BladeCustomTest.php b/tests/View/Blade/BladeCustomTest.php index c68fd5d759bf..de44c5b25619 100644 --- a/tests/View/Blade/BladeCustomTest.php +++ b/tests/View/Blade/BladeCustomTest.php @@ -91,6 +91,19 @@ public function testCustomIfElseConditions() $this->assertEquals($expected, $this->compiler->compileString($string)); } + public function testCustomConditionsAccepts0AsArgument() + { + $this->compiler->if('custom', function ($user) { + return true; + }); + + $string = '@custom(0) +@endcustom'; + $expected = ' +'; + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + public function testCustomComponents() { $this->compiler->component('app.components.alert', 'alert'); From 75558919d905d7fd01a1be9931ad59c996dcf317 Mon Sep 17 00:00:00 2001 From: tjallingt Date: Thu, 31 May 2018 15:35:27 +0200 Subject: [PATCH 2/2] added missing else conditional test --- tests/View/Blade/BladeCustomTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/View/Blade/BladeCustomTest.php b/tests/View/Blade/BladeCustomTest.php index de44c5b25619..c49dceaf6338 100644 --- a/tests/View/Blade/BladeCustomTest.php +++ b/tests/View/Blade/BladeCustomTest.php @@ -93,13 +93,15 @@ public function testCustomIfElseConditions() public function testCustomConditionsAccepts0AsArgument() { - $this->compiler->if('custom', function ($user) { + $this->compiler->if('custom', function ($number) { return true; }); $string = '@custom(0) +@elsecustom(0) @endcustom'; $expected = ' + '; $this->assertEquals($expected, $this->compiler->compileString($string)); }