diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index fa2ce2f..87a73f8 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -84,7 +84,7 @@ public function __construct($options = array()) { // 3. add String loader // This *must* go last or no loaders after will work ~ https://github.com/symfony/symfony/issues/10865 // @todo Remove `Twig_Loader_String` - if a Twig include path is wrong, this outputs the string anyway with no error ~ https://github.com/symfony/symfony/issues/10865 - $loaders[] = new \Twig_Loader_String(); + $loaders[] = new Twig\ConditionalStringLoader(); // set-up Twig $twigLoader = new \Twig_Loader_Chain($loaders); diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php index e81c9b7..276ad7d 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php @@ -48,7 +48,7 @@ public function __construct($options = array()) { if (count($filesystemLoaderPaths) > 0) { $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); } - $loaders[] = new \Twig_Loader_String(); + $loaders[] = new Twig\ConditionalStringLoader(); // set-up Twig $twigLoader = new \Twig_Loader_Chain($loaders); diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/Twig/ConditionalStringLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/Twig/ConditionalStringLoader.php new file mode 100644 index 0000000..f8e814b --- /dev/null +++ b/src/PatternLab/PatternEngine/Twig/Loaders/Twig/ConditionalStringLoader.php @@ -0,0 +1,31 @@ +exists($name)) { + return parent::getSourceContext($name); + } + return null; + } + + /** + * Return false if $name looks like a simple file name, true otherwise. + * + * A simple file name is a simple string consisting of alphanumerics, + * periods, hyphens, underbars, and so on, otherwise + */ + public function exists($name) { + return preg_match("/^[-a-zA-Z0-9~\\.\\/_@]+$/", $name) === 0; + } +}