You are here

protected function Twig_Loader_Filesystem::validateName in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Loader/Filesystem.php \Twig_Loader_Filesystem::validateName()
1 call to Twig_Loader_Filesystem::validateName()
Twig_Loader_Filesystem::findTemplate in vendor/twig/twig/lib/Twig/Loader/Filesystem.php

File

vendor/twig/twig/lib/Twig/Loader/Filesystem.php, line 239

Class

Twig_Loader_Filesystem
Loads template from the filesystem.

Code

protected function validateName($name) {
  if (false !== strpos($name, "\0")) {
    throw new Twig_Error_Loader('A template name cannot contain NUL bytes.');
  }
  $name = ltrim($name, '/');
  $parts = explode('/', $name);
  $level = 0;
  foreach ($parts as $part) {
    if ('..' === $part) {
      --$level;
    }
    elseif ('.' !== $part) {
      ++$level;
    }
    if ($level < 0) {
      throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
    }
  }
}