mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
normalizePath: Do not mangle phar URLs.
This commit is contained in:
committed by
Fabien Potencier
parent
52e9e01353
commit
7dd63fc087
@@ -257,11 +257,12 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
private function normalizePath($path)
|
||||
{
|
||||
$parts = explode('/', str_replace('\\', '/', $path));
|
||||
$isPhar = strpos($path, 'phar://') === 0;
|
||||
$new = array();
|
||||
foreach ($parts as $i => $part) {
|
||||
if ('..' === $part) {
|
||||
array_pop($new);
|
||||
} elseif ('.' !== $part && ('' !== $part || 0 === $i)) {
|
||||
} elseif ('.' !== $part && ('' !== $part || 0 === $i || $isPhar && $i < 3)) {
|
||||
$new[] = $part;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,4 +179,17 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
$template = $twig->loadTemplate($templateName);
|
||||
$this->assertSame('VALID Child', $template->renderBlock('body', array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.3
|
||||
*/
|
||||
public function testLoadTemplateFromPhar()
|
||||
{
|
||||
$loader = new Twig_Loader_Filesystem(array());
|
||||
// phar-sample.phar was created with the following script:
|
||||
// $f = new Phar('phar-test.phar');
|
||||
// $f->addFromString('hello.twig', 'hello from phar');
|
||||
$loader->addPath('phar://'.dirname(__FILE__).'/Fixtures/phar/phar-sample.phar');
|
||||
$this->assertSame('hello from phar', $loader->getSource('hello.twig'));
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user