Skip to content

Commit

Permalink
fix parse exception "Variable was not properly terminated" with line …
Browse files Browse the repository at this point in the history
…break (#162)
  • Loading branch information
PNixx authored Mar 22, 2022
1 parent 948327d commit 1dbd10e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Liquid/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private function blockName()
*/
private function createVariable($token)
{
$variableRegexp = new Regexp('/^' . Liquid::get('VARIABLE_START') . Liquid::get('WHITESPACE_CONTROL') . '?(.*?)' . Liquid::get('WHITESPACE_CONTROL') . '?' . Liquid::get('VARIABLE_END') . '$/');
$variableRegexp = new Regexp('/^' . Liquid::get('VARIABLE_START') . Liquid::get('WHITESPACE_CONTROL') . '?(.*?)' . Liquid::get('WHITESPACE_CONTROL') . '?' . Liquid::get('VARIABLE_END') . '$/s');
if ($variableRegexp->match($token)) {
return new Variable($variableRegexp->matches[1]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Liquid/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct($markup)
$this->markup = $markup;

$filterSep = new Regexp('/' . Liquid::get('FILTER_SEPARATOR') . '\s*(.*)/m');
$syntaxParser = new Regexp('/(' . Liquid::get('QUOTED_FRAGMENT') . ')(.*)/m');
$syntaxParser = new Regexp('/(' . Liquid::get('QUOTED_FRAGMENT') . ')(.*)/ms');
$filterParser = new Regexp('/(?:\s+|' . Liquid::get('QUOTED_FRAGMENT') . '|' . Liquid::get('ARGUMENT_SEPARATOR') . ')+/');
$filterArgsRegex = new Regexp('/(?:' . Liquid::get('FILTER_ARGUMENT_SEPARATOR') . '|' . Liquid::get('ARGUMENT_SEPARATOR') . ')\s*((?:\w+\s*\:\s*)?' . Liquid::get('QUOTED_FRAGMENT') . ')/');

Expand Down
3 changes: 0 additions & 3 deletions tests/Liquid/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ public function testLinkTo()
*/
public function testVariableWithANewLine()
{
$this->expectException(\Liquid\Exception\ParseException::class);
$this->expectExceptionMessage('was not properly terminated');

$text = "{{ aaa\n }}";
$this->assertTemplateResult('', $text, $this->assigns);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Liquid/VariableResolutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public function testIgnoreUnknown()
$this->assertEquals('', $template->render());
}

public function testLineBreak()
{
$template = new Template();

$template->parse("{{ test |\n strip_html }}");
$this->assertEquals('worked', $template->render(array('test' => '<b>worked</b>')));
}

public function testArrayScoping()
{
$template = new Template();
Expand Down

0 comments on commit 1dbd10e

Please sign in to comment.