Skip to content

Commit f89617c

Browse files
author
fkulakov
committed
Issue-26357
Normalize view paths within FileViewFinder.
1 parent dfe84e6 commit f89617c

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/Illuminate/View/FileViewFinder.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FileViewFinder implements ViewFinderInterface
5353
public function __construct(Filesystem $files, array $paths, array $extensions = null)
5454
{
5555
$this->files = $files;
56-
$this->paths = $paths;
56+
$this->paths = array_map([$this, 'normalizePath'], $paths);
5757

5858
if (isset($extensions)) {
5959
$this->extensions = $extensions;
@@ -158,7 +158,7 @@ protected function getPossibleViewFiles($name)
158158
*/
159159
public function addLocation($location)
160160
{
161-
$this->paths[] = $location;
161+
$this->paths[] = $this->normalizePath($location);
162162
}
163163

164164
/**
@@ -169,7 +169,7 @@ public function addLocation($location)
169169
*/
170170
public function prependLocation($location)
171171
{
172-
array_unshift($this->paths, $location);
172+
array_unshift($this->paths, $this->normalizePath($location));
173173
}
174174

175175
/**
@@ -295,4 +295,15 @@ public function getExtensions()
295295
{
296296
return $this->extensions;
297297
}
298+
299+
/**
300+
* Replace unnecessary relative fragments from the absolute view path.
301+
*
302+
* @param string $path
303+
* @return string
304+
*/
305+
protected function normalizePath($path)
306+
{
307+
return realpath($path) ?: $path;
308+
}
298309
}

tests/View/ViewFileViewFinderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ public function testPassingViewWithFalseHintReturnsFalse()
145145
$this->assertFalse($finder->hasHintInformation('::foo.bar'));
146146
}
147147

148+
public function pathsProvider()
149+
{
150+
return [
151+
['incorrect_path', 'incorrect_path'],
152+
];
153+
}
154+
155+
/**
156+
* @dataProvider pathsProvider
157+
*/
158+
public function testNormalizedPaths($originalPath, $exceptedPath)
159+
{
160+
$finder = $this->getFinder();
161+
$finder->prependLocation($originalPath);
162+
$normalizedPath = $finder->getPaths()[0];
163+
$this->assertSame($exceptedPath, $normalizedPath);
164+
}
165+
148166
protected function getFinder()
149167
{
150168
return new FileViewFinder(m::mock(Filesystem::class), [__DIR__]);

0 commit comments

Comments
 (0)