Skip to content

Commit a53fb9d

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
2 parents 51a72d0 + 3e89be1 commit a53fb9d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Templating/TemplateNameParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function parse($name)
5555
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
5656
}
5757

58-
if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
58+
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || $this->isAbsolutePath($name) || 0 === strpos($name, '@')) {
5959
return parent::parse($name);
6060
}
6161

@@ -71,4 +71,9 @@ public function parse($name)
7171

7272
return $this->cache[$name] = $template;
7373
}
74+
75+
private function isAbsolutePath($file)
76+
{
77+
return (bool) preg_match('#^(?:/|[a-zA-Z]:)#', $file);
78+
}
7479
}

Tests/Templating/TemplateNameParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public function parseProvider()
6666
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
6767
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
6868
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')),
69+
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')),
70+
array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
71+
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')),
72+
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')),
73+
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')),
74+
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')),
6975
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
7076
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
7177
array('name', 'name', 'name', new BaseTemplateReference('name')),

0 commit comments

Comments
 (0)