Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f69cf39

Browse files
committed
Ensure content and escaped tags are not quotted when set
1 parent 276c5c4 commit f69cf39

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

src/Illuminate/View/Compilers/BladeCompiler.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ protected function compileExtensions($value)
177177
*/
178178
protected function compileComments($value)
179179
{
180-
$pattern = sprintf('/%s--((.|\s)*?)--%s/', $this->contentTags[0], $this->contentTags[1]);
180+
$contentTags = $this->quoteTags($this->contentTags);
181+
182+
$pattern = sprintf('/%s--((.|\s)*?)--%s/', $contentTags[0], $contentTags[1]);
181183

182184
return preg_replace($pattern, '<?php /*$1*/ ?>', $value);
183185
}
@@ -190,7 +192,11 @@ protected function compileComments($value)
190192
*/
191193
protected function compileEchos($value)
192194
{
193-
$difference = strlen($this->contentTags[0]) - strlen($this->escapedTags[0]);
195+
$contentTags = $this->quoteTags($this->contentTags);
196+
197+
$escapedTags = $this->quoteTags($this->escapedTags);
198+
199+
$difference = strlen($contentTags[0]) - strlen($escapedTags[0]);
194200

195201
if ($difference > 0)
196202
{
@@ -229,7 +235,9 @@ protected function compileStatements($value)
229235
*/
230236
protected function compileRegularEchos($value)
231237
{
232-
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->contentTags[0], $this->contentTags[1]);
238+
$contentTags = $this->quoteTags($this->contentTags);
239+
240+
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $contentTags[0], $contentTags[1]);
233241

234242
$callback = function($matches)
235243
{
@@ -249,7 +257,9 @@ protected function compileRegularEchos($value)
249257
*/
250258
protected function compileEscapedEchos($value)
251259
{
252-
$pattern = sprintf('/%s\s*(.+?)\s*%s(\r?\n)?/s', $this->escapedTags[0], $this->escapedTags[1]);
260+
$escapedTags = $this->quoteTags($this->escapedTags);
261+
262+
$pattern = sprintf('/%s\s*(.+?)\s*%s(\r?\n)?/s', $escapedTags[0], $escapedTags[1]);
253263

254264
$callback = function($matches)
255265
{
@@ -676,7 +686,7 @@ public function setContentTags($openTag, $closeTag, $escaped = false)
676686
{
677687
$property = ($escaped === true) ? 'escapedTags' : 'contentTags';
678688

679-
$this->{$property} = array(preg_quote($openTag), preg_quote($closeTag));
689+
$this->{$property} = array($openTag, $closeTag);
680690
}
681691

682692
/**
@@ -711,4 +721,18 @@ public function getEscapedContentTags()
711721
return $this->escapedTags;
712722
}
713723

724+
/**
725+
* Quote tags.
726+
*
727+
* @param array $tags
728+
* @return array
729+
*/
730+
protected function quoteTags($tags)
731+
{
732+
return [
733+
preg_quote($tags[0]),
734+
preg_quote($tags[1]),
735+
];
736+
}
737+
714738
}

tests/View/ViewBladeCompilerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,24 @@ public function testExpressionWithinHTML()
456456
}
457457

458458

459+
public function testSetAndRetriveContentTags()
460+
{
461+
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
462+
$this->assertEquals(['{{', '}}'], $compiler->getContentTags());
463+
$compiler->setContentTags('{{', '}}');
464+
$this->assertEquals(['{{', '}}'], $compiler->getContentTags());
465+
}
466+
467+
468+
public function testSetAndRetriveEscapedTags()
469+
{
470+
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
471+
$this->assertEquals(['{{{', '}}}'], $compiler->getEscapedContentTags());
472+
$compiler->setContentTags('{{{', '}}}');
473+
$this->assertEquals(['{{{', '}}}'], $compiler->getEscapedContentTags());
474+
}
475+
476+
459477
protected function getFiles()
460478
{
461479
return m::mock('Illuminate\Filesystem\Filesystem');

0 commit comments

Comments
 (0)