Skip to content

Commit

Permalink
Fix block parsing when raw fragment is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Oct 25, 2024
1 parent 3d81819 commit 7d33acd
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Phalcon\Volt\Parser;

use Phalcon\Volt\Compiler;
use Phalcon\Volt\Exception;
use Phalcon\Volt\Scanner\Opcode;
use Phalcon\Volt\Scanner\Scanner;
use Phalcon\Volt\Scanner\State;
Expand All @@ -37,6 +38,7 @@ public function __construct(private string $code)
* @param string $templatePath
*
* @return array
* @throws Exception
*/
public function parseView(string $templatePath): array
{
Expand Down Expand Up @@ -386,24 +388,26 @@ public function parseView(string $templatePath): array
break;

case Compiler::PHVOLT_T_RAW_FRAGMENT:
if ($state->extendsMode === 1 && $state->blockLevel === 0) {
$this->createErrorMessage(
$parserStatus,
'Child templates only may contain blocks'
);
$parserStatus->setStatus(Status::PHVOLT_PARSING_FAILED);
break;
}
if ($state->rawFragment !== '') {
if ($state->extendsMode === 1 && $state->blockLevel === 0) {
$this->createErrorMessage(
$parserStatus,
'Child templates only may contain blocks'
);
$parserStatus->setStatus(Status::PHVOLT_PARSING_FAILED);
break;
}

if (!$this->phvoltIsBlankString($this->token)) {
$state->statementPosition++;
}

if (!$this->phvoltIsBlankString($this->token)) {
$state->statementPosition++;
$this->phvoltParseWithToken(
$parser,
Compiler::PHVOLT_T_RAW_FRAGMENT,
Opcode::PHVOLT_RAW_FRAGMENT
);
}

$this->phvoltParseWithToken(
$parser,
Compiler::PHVOLT_T_RAW_FRAGMENT,
Opcode::PHVOLT_RAW_FRAGMENT
);
break;

case Compiler::PHVOLT_T_SET:
Expand Down Expand Up @@ -595,7 +599,7 @@ public function parseView(string $templatePath): array
}

if ($parserStatus->getStatus() !== Status::PHVOLT_PARSING_OK) {
break;
throw new Exception($parserStatus->getSyntaxError());
}

$state->setEnd($state->getStart());
Expand Down

0 comments on commit 7d33acd

Please sign in to comment.