From a422ff22328b031bdbc0a3bb7b3ce19cd06279e5 Mon Sep 17 00:00:00 2001 From: ockle Date: Mon, 3 Jul 2017 18:50:43 +0100 Subject: [PATCH 1/3] don't re-escape a View instance passed as the default value to @yield --- .../View/Concerns/ManagesLayouts.php | 3 ++- tests/View/ViewFactoryTest.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/Concerns/ManagesLayouts.php b/src/Illuminate/View/Concerns/ManagesLayouts.php index c9fc1e2cdd74..cdec0d43a08e 100644 --- a/src/Illuminate/View/Concerns/ManagesLayouts.php +++ b/src/Illuminate/View/Concerns/ManagesLayouts.php @@ -2,6 +2,7 @@ namespace Illuminate\View\Concerns; +use Illuminate\Contracts\View\View; use InvalidArgumentException; trait ManagesLayouts @@ -143,7 +144,7 @@ protected function extendSection($section, $content) */ public function yieldContent($section, $default = '') { - $sectionContent = e($default); + $sectionContent = $default instanceof View ? $default : e($default); if (isset($this->sections[$section])) { $sectionContent = $this->sections[$section]; diff --git a/tests/View/ViewFactoryTest.php b/tests/View/ViewFactoryTest.php index 23afb6157e4f..005d7ae5853f 100755 --- a/tests/View/ViewFactoryTest.php +++ b/tests/View/ViewFactoryTest.php @@ -202,6 +202,26 @@ public function testRenderCountHandling() $this->assertTrue($factory->doneRendering()); } + public function testYieldDefault() + { + $factory = $this->getFactory(); + $this->assertEquals('hi', $factory->yieldContent('foo', 'hi')); + } + + public function testYieldDefaultIsEscaped() + { + $factory = $this->getFactory(); + $this->assertEquals('<p>hi</p>', $factory->yieldContent('foo', '

hi

')); + } + + public function testYieldDefaultViewIsNotEscapedTwice() + { + $factory = $this->getFactory(); + $view = m::mock('Illuminate\View\View'); + $view->shouldReceive('__toString')->once()->andReturn('

hi

<p>already escaped</p>'); + $this->assertEquals('

hi

<p>already escaped</p>', $factory->yieldContent('foo', $view)); + } + public function testBasicSectionHandling() { $factory = $this->getFactory(); From e853e15af3a528ad2c1571dafc54b47bd216c96b Mon Sep 17 00:00:00 2001 From: ockle Date: Mon, 3 Jul 2017 19:04:13 +0100 Subject: [PATCH 2/3] don't re-escape a View instance passed as the default value to @section --- .../View/Concerns/ManagesLayouts.php | 2 +- tests/View/ViewFactoryTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/Concerns/ManagesLayouts.php b/src/Illuminate/View/Concerns/ManagesLayouts.php index cdec0d43a08e..bd75a1695c24 100644 --- a/src/Illuminate/View/Concerns/ManagesLayouts.php +++ b/src/Illuminate/View/Concerns/ManagesLayouts.php @@ -42,7 +42,7 @@ public function startSection($section, $content = null) $this->sectionStack[] = $section; } } else { - $this->extendSection($section, e($content)); + $this->extendSection($section, $content instanceof View ? $content : e($content)); } } diff --git a/tests/View/ViewFactoryTest.php b/tests/View/ViewFactoryTest.php index 005d7ae5853f..571525ae63fe 100755 --- a/tests/View/ViewFactoryTest.php +++ b/tests/View/ViewFactoryTest.php @@ -231,6 +231,29 @@ public function testBasicSectionHandling() $this->assertEquals('hi', $factory->yieldContent('foo')); } + public function testBasicSectionDefault() + { + $factory = $this->getFactory(); + $factory->startSection('foo', 'hi'); + $this->assertEquals('hi', $factory->yieldContent('foo')); + } + + public function testBasicSectionDefaultIsEscaped() + { + $factory = $this->getFactory(); + $factory->startSection('foo', '

hi

'); + $this->assertEquals('<p>hi</p>', $factory->yieldContent('foo')); + } + + public function testBasicSectionDefaultViewIsNotEscapedTwice() + { + $factory = $this->getFactory(); + $view = m::mock('Illuminate\View\View'); + $view->shouldReceive('__toString')->once()->andReturn('

hi

<p>already escaped</p>'); + $factory->startSection('foo', $view); + $this->assertEquals('

hi

<p>already escaped</p>', $factory->yieldContent('foo')); + } + public function testSectionExtending() { $placeholder = \Illuminate\View\Factory::parentPlaceholder('foo'); From 1e573739b565696127e0c799d8ff00e38b4609ce Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 3 Jul 2017 15:34:07 -0500 Subject: [PATCH 3/3] Update ManagesLayouts.php --- src/Illuminate/View/Concerns/ManagesLayouts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/View/Concerns/ManagesLayouts.php b/src/Illuminate/View/Concerns/ManagesLayouts.php index bd75a1695c24..b3b4aefe3699 100644 --- a/src/Illuminate/View/Concerns/ManagesLayouts.php +++ b/src/Illuminate/View/Concerns/ManagesLayouts.php @@ -2,8 +2,8 @@ namespace Illuminate\View\Concerns; -use Illuminate\Contracts\View\View; use InvalidArgumentException; +use Illuminate\Contracts\View\View; trait ManagesLayouts {