mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 03:57:21 +00:00
Fix: A template name cannot be an absolute path
This commit is contained in:
committed by
Fabien Potencier
parent
9773024395
commit
3a67fc7dc5
@@ -292,6 +292,10 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
|
||||
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, '/');
|
||||
$parts = explode('/', $name);
|
||||
$level = 0;
|
||||
|
||||
@@ -32,11 +32,13 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
$loader = new FilesystemLoader([__DIR__.'/../Fixtures']);
|
||||
|
||||
$this->expectException(LoaderError::class);
|
||||
try {
|
||||
$loader->getCacheKey($template);
|
||||
$this->fail();
|
||||
} catch (LoaderError $e) {
|
||||
$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'],
|
||||
['/../AutoloaderTest.php'],
|
||||
['/AutoloaderTest.php'],
|
||||
['\\AutoloaderTest.php'],
|
||||
['//AutoloaderTest.php'],
|
||||
['\\\\AutoloaderTest.php'],
|
||||
['/./AutoloaderTest.php'],
|
||||
['\\.\\AutoloaderTest.php'],
|
||||
['C:/AutoloaderTest.php'],
|
||||
['C:\\AutoloaderTest.php'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user