Skip to content

Commit

Permalink
Merge pull request #4191 from kenjis/fix-Parser-render
Browse files Browse the repository at this point in the history
Fix Parser file path in ViewException message is empty
  • Loading branch information
paulbalandan authored Jan 30, 2021
2 parents 05a836a + 6db7e1c commit 457e71d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 9 additions & 8 deletions system/View/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ public function render(string $view, array $options = null, bool $saveData = nul

if (! is_file($file))
{
$file = $this->loader->locateFile($view, 'Views');
}
$fileOrig = $file;
$file = $this->loader->locateFile($view, 'Views');

// locateFile will return an empty string if the file cannot be found.
if (empty($file))
{
throw ViewException::forInvalidFile($file);
// locateFile will return an empty string if the file cannot be found.
if (empty($file))
{
throw ViewException::forInvalidFile($fileOrig);
}
}

if (is_null($this->tempData))
Expand Down Expand Up @@ -328,8 +329,8 @@ protected function parsePair(string $variable, array $data, string $template): a
// Find all matches of space-flexible versions of {tag}{/tag} so we
// have something to loop over.
preg_match_all(
'#' . $this->leftDelimiter . '\s*' . preg_quote($variable) . '\s*' . $this->rightDelimiter . '(.+?)' .
$this->leftDelimiter . '\s*' . '/' . preg_quote($variable) . '\s*' . $this->rightDelimiter . '#s', $template, $matches, PREG_SET_ORDER
'#' . $this->leftDelimiter . '\s*' . preg_quote($variable) . '\s*' . $this->rightDelimiter . '(.+?)' .
$this->leftDelimiter . '\s*' . '/' . preg_quote($variable) . '\s*' . $this->rightDelimiter . '#s', $template, $matches, PREG_SET_ORDER
);

/*
Expand Down
2 changes: 2 additions & 0 deletions tests/system/View/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@ public function testRenderFindsView()
public function testRenderCannotFindView()
{
$this->expectException(ViewException::class);
$this->expectExceptionMessageMatches('!/View/Views/Simplest\.php\z!');

$this->parser->setData(['testString' => 'Hello World']);
$this->parser->render('Simplest');
}
Expand Down

0 comments on commit 457e71d

Please sign in to comment.