diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index cb4df85..0176208 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -127,6 +127,11 @@ public function getCacheFilename($name) { $class = substr($this->getTemplateClass($name), strlen($this->templateClassPrefix)); // The first part is what is invalidated. + if (strpos($name, '{# inline_template_start #}') !== FALSE) { + // $name is an inline template, and can have characters that are not valid + // for a filename. + $name = 'inline-template-' . hash('sha256', $name); + } return $this->templateCacheFilenamePrefix . '_' . basename($name) . '_' . $class; } diff --git a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php index 1bab9bf..07eb8ae 100644 --- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php +++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php @@ -65,6 +65,13 @@ public function testInlineTemplate() { // Render it twice so that twig caching is triggered. $this->assertEqual($renderer->renderRoot($element), 'test-with-context muuh'); $this->assertEqual($renderer->renderRoot($element_copy), 'test-with-context muuh'); + + // Tests caching of inline templates. + $name = '{# inline_template_start #}test-with-context {{ llama }}'; + $hash = $this->container->getParameter('twig_extension_hash'); + $class = substr($environment->getTemplateClass($name), strlen('__TwigTemplate_')); + $expected = $hash . '_inline-template-' . hash('sha256', $name) . '_' . $class; + $this->assertEqual($expected, $environment->getCacheFilename($name)); } /**