Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/Liquid/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@

private ?Regexp $variableRegexp;

public function __construct($markup, array &$tokens, ?FileSystem $fileSystem = null)
{
$this->config = &Liquid::$config;

$this->startRegexp = new Regexp('/^' . $this->config['TAG_START'] . '/');
$this->tagRegexp = new Regexp('/^' . $this->config['TAG_START'] . $this->config['WHITESPACE_CONTROL'] . '?\s*(\w+)\s*(.*?)' . $this->config['WHITESPACE_CONTROL'] . '?' . $this->config['TAG_END'] . '$/s');
$this->variableStartRegexp = new Regexp('/^' . $this->config['VARIABLE_START'] . '/');
$this->whitespaceControl = $this->config['WHITESPACE_CONTROL'];
$this->variableRegexp = new Regexp('/^' . $this->config['VARIABLE_START'] . $this->config['WHITESPACE_CONTROL'] . '?(.*?)' . $this->config['WHITESPACE_CONTROL'] . '?' . $this->config['VARIABLE_END'] . '$/s');

parent::__construct($markup, $tokens, $fileSystem);
}

/**
* @return array
*/
Expand All @@ -60,10 +73,6 @@
*/
public function parse(array &$tokens)
{
// Constructor is not reliably called by subclasses, so we need to ensure these are set
$this->startRegexp ??= new Regexp('/^' . Liquid::get('TAG_START') . '/');
$this->tagRegexp ??= new Regexp('/^' . Liquid::get('TAG_START') . Liquid::get('WHITESPACE_CONTROL') . '?\s*(\w+)\s*(.*?)' . Liquid::get('WHITESPACE_CONTROL') . '?' . Liquid::get('TAG_END') . '$/s');
$this->variableStartRegexp ??= new Regexp('/^' . Liquid::get('VARIABLE_START') . '/');

$startRegexp = $this->startRegexp;
$tagRegexp = $this->tagRegexp;
Expand Down Expand Up @@ -132,7 +141,6 @@
*/
protected function whitespaceHandler($token)
{
$this->whitespaceControl ??= Liquid::get('WHITESPACE_CONTROL');

/*
* This assumes that TAG_START is always '{%', and a whitespace control indicator
Expand Down Expand Up @@ -205,7 +213,7 @@
/**
* An action to execute when the end tag is reached
*/
protected function endTag()

Check warning on line 216 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "ProtectedVisibility": @@ @@ /** * An action to execute when the end tag is reached */ - protected function endTag() + private function endTag() { // Do nothing by default }
{
// Do nothing by default
}
Expand All @@ -223,9 +231,9 @@
{
switch ($tag) {
case 'else':
throw new ParseException($this->blockName() . " does not expect else tag");

Check warning on line 234 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ { switch ($tag) { case 'else': - throw new ParseException($this->blockName() . " does not expect else tag"); + throw new ParseException(" does not expect else tag"); case 'end': throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); default:

Check warning on line 234 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "Concat": @@ @@ { switch ($tag) { case 'else': - throw new ParseException($this->blockName() . " does not expect else tag"); + throw new ParseException(" does not expect else tag" . $this->blockName()); case 'end': throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); default:
case 'end':
throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter());

Check warning on line 236 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ case 'else': throw new ParseException($this->blockName() . " does not expect else tag"); case 'end': - throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); + throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use "); default: throw new ParseException("Unknown tag {$tag}"); }

Check warning on line 236 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "Concat": @@ @@ case 'else': throw new ParseException($this->blockName() . " does not expect else tag"); case 'end': - throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); + throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . $this->blockDelimiter() . " tags. Use "); default: throw new ParseException("Unknown tag {$tag}"); }

Check warning on line 236 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ case 'else': throw new ParseException($this->blockName() . " does not expect else tag"); case 'end': - throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); + throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . $this->blockDelimiter()); default: throw new ParseException("Unknown tag {$tag}"); }

Check warning on line 236 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "Concat": @@ @@ case 'else': throw new ParseException($this->blockName() . " does not expect else tag"); case 'end': - throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); + throw new ParseException("'end' is not a valid delimiter for " . " tags. Use " . $this->blockName() . $this->blockDelimiter()); default: throw new ParseException("Unknown tag {$tag}"); }

Check warning on line 236 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ case 'else': throw new ParseException($this->blockName() . " does not expect else tag"); case 'end': - throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); + throw new ParseException("'end' is not a valid delimiter for " . " tags. Use " . $this->blockDelimiter()); default: throw new ParseException("Unknown tag {$tag}"); }

Check warning on line 236 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ case 'else': throw new ParseException($this->blockName() . " does not expect else tag"); case 'end': - throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); + throw new ParseException($this->blockName() . " tags. Use " . $this->blockDelimiter()); default: throw new ParseException("Unknown tag {$tag}"); }

Check warning on line 236 in src/Liquid/AbstractBlock.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Escaped Mutant for Mutator "Concat": @@ @@ case 'else': throw new ParseException($this->blockName() . " does not expect else tag"); case 'end': - throw new ParseException("'end' is not a valid delimiter for " . $this->blockName() . " tags. Use " . $this->blockDelimiter()); + throw new ParseException($this->blockName() . "'end' is not a valid delimiter for " . " tags. Use " . $this->blockDelimiter()); default: throw new ParseException("Unknown tag {$tag}"); }
default:
throw new ParseException("Unknown tag $tag");
}
Expand Down Expand Up @@ -274,7 +282,6 @@
*/
private function createVariable($token)
{
$this->variableRegexp ??= new Regexp('/^' . Liquid::get('VARIABLE_START') . Liquid::get('WHITESPACE_CONTROL') . '?(.*?)' . Liquid::get('WHITESPACE_CONTROL') . '?' . Liquid::get('VARIABLE_END') . '$/s');

if ($this->variableRegexp->match($token)) {
return new Variable($this->variableRegexp->matches[1]);
Expand Down
Loading