Fix: A template name cannot be an absolute path

This commit is contained in:
Michael Voříšek
2021-04-06 03:10:12 +02:00
committed by Fabien Potencier
parent 9773024395
commit 3a67fc7dc5
2 changed files with 15 additions and 1 deletions
+4
View File
@@ -292,6 +292,10 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
throw new LoaderError('A template name cannot contain NUL bytes.'); throw new LoaderError('A template name cannot contain NUL bytes.');
} }
if ($this->isAbsolutePath($name)) {
throw new LoaderError(sprintf('A template name cannot be an absolute path (%s).', $name));
}
$name = ltrim($name, '/'); $name = ltrim($name, '/');
$parts = explode('/', $name); $parts = explode('/', $name);
$level = 0; $level = 0;
+11 -1
View File
@@ -32,11 +32,13 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase
{ {
$loader = new FilesystemLoader([__DIR__.'/../Fixtures']); $loader = new FilesystemLoader([__DIR__.'/../Fixtures']);
$this->expectException(LoaderError::class);
try { try {
$loader->getCacheKey($template); $loader->getCacheKey($template);
$this->fail();
} catch (LoaderError $e) { } catch (LoaderError $e) {
$this->assertStringNotContainsString('Unable to find template', $e->getMessage()); $this->assertStringNotContainsString('Unable to find template', $e->getMessage());
throw $e;
} }
} }
@@ -62,6 +64,14 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase
['filters\\\\..\\\\..\\\\AutoloaderTest.php'], ['filters\\\\..\\\\..\\\\AutoloaderTest.php'],
['filters\\//../\\/\\..\\AutoloaderTest.php'], ['filters\\//../\\/\\..\\AutoloaderTest.php'],
['/../AutoloaderTest.php'], ['/../AutoloaderTest.php'],
['/AutoloaderTest.php'],
['\\AutoloaderTest.php'],
['//AutoloaderTest.php'],
['\\\\AutoloaderTest.php'],
['/./AutoloaderTest.php'],
['\\.\\AutoloaderTest.php'],
['C:/AutoloaderTest.php'],
['C:\\AutoloaderTest.php'],
]; ];
} }