[FrameworkBundle] Fix a regression in handling absolute and namespaced template paths
This commit is contained in:
parent
baf35cf3c0
commit
d8c493f076
@ -56,7 +56,7 @@ class TemplateNameParser extends BaseTemplateNameParser
|
|||||||
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
|
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
|
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || $this->isAbsolutePath($name) || 0 === strpos($name, '@')) {
|
||||||
return parent::parse($name);
|
return parent::parse($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,4 +72,9 @@ class TemplateNameParser extends BaseTemplateNameParser
|
|||||||
|
|
||||||
return $this->cache[$name] = $template;
|
return $this->cache[$name] = $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isAbsolutePath($file)
|
||||||
|
{
|
||||||
|
return (bool) preg_match('#^(?:/|[a-zA-Z]:)#', $file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,12 @@ class TemplateNameParserTest extends TestCase
|
|||||||
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
||||||
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
||||||
array('FooBundle:Post:foo.bar.index.html.php', 'FooBundle:Post:foo.bar.index.html.php', '@FooBundle/Resources/views/Post/foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
|
array('FooBundle:Post:foo.bar.index.html.php', 'FooBundle:Post:foo.bar.index.html.php', '@FooBundle/Resources/views/Post/foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
|
||||||
|
array('@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', new BaseTemplateReference('@FooBundle/Resources/views/layout.html.twig', 'twig')),
|
||||||
|
array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
|
||||||
|
array('/path/to/section/index.html.php', '/path/to/section/index.html.php', '/path/to/section/index.html.php', new BaseTemplateReference('/path/to/section/index.html.php', 'php')),
|
||||||
|
array('C:\\path\\to\\section\\name.html.php', 'C:path/to/section/name.html.php', 'C:path/to/section/name.html.php', new BaseTemplateReference('C:path/to/section/name.html.php', 'php')),
|
||||||
|
array('C:\\path\\to\\section\\name:foo.html.php', 'C:path/to/section/name:foo.html.php', 'C:path/to/section/name:foo.html.php', new BaseTemplateReference('C:path/to/section/name:foo.html.php', 'php')),
|
||||||
|
array('\\path\\to\\section\\name.html.php', '/path/to/section/name.html.php', '/path/to/section/name.html.php', new BaseTemplateReference('/path/to/section/name.html.php', 'php')),
|
||||||
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
|
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
|
||||||
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
|
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
|
||||||
array('name', 'name', 'name', new BaseTemplateReference('name')),
|
array('name', 'name', 'name', new BaseTemplateReference('name')),
|
||||||
|
Reference in New Issue
Block a user