Skip to content

Commit 457e71d

Browse files
authored
Merge pull request #4191 from kenjis/fix-Parser-render
Fix Parser file path in ViewException message is empty
2 parents 05a836a + 6db7e1c commit 457e71d

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

system/View/Parser.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ public function render(string $view, array $options = null, bool $saveData = nul
117117

118118
if (! is_file($file))
119119
{
120-
$file = $this->loader->locateFile($view, 'Views');
121-
}
120+
$fileOrig = $file;
121+
$file = $this->loader->locateFile($view, 'Views');
122122

123-
// locateFile will return an empty string if the file cannot be found.
124-
if (empty($file))
125-
{
126-
throw ViewException::forInvalidFile($file);
123+
// locateFile will return an empty string if the file cannot be found.
124+
if (empty($file))
125+
{
126+
throw ViewException::forInvalidFile($fileOrig);
127+
}
127128
}
128129

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

335336
/*

tests/system/View/ParserTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,8 @@ public function testRenderFindsView()
942942
public function testRenderCannotFindView()
943943
{
944944
$this->expectException(ViewException::class);
945+
$this->expectExceptionMessageMatches('!/View/Views/Simplest\.php\z!');
946+
945947
$this->parser->setData(['testString' => 'Hello World']);
946948
$this->parser->render('Simplest');
947949
}

0 commit comments

Comments
 (0)