mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
Prevent potential doc comments in escaped inlined source
This commit is contained in:
@@ -647,7 +647,7 @@ class Twig_Environment
|
||||
$compiled = $this->compile($this->parse($this->tokenize($source, $name)), $source);
|
||||
|
||||
if (isset($source[0])) {
|
||||
$compiled .= '/* '.str_replace(array('*/', "\r\n", "\n", "\r"), array('*//*', "\n", "*/\n/* ", "*/\n/* "), $source)."*/\n";
|
||||
$compiled .= '/* '.str_replace(array('*/', "\r\n", "\r", "\n"), array('*//* ', "\n", "\n", "*/\n/* "), $source)."*/\n";
|
||||
}
|
||||
|
||||
return $compiled;
|
||||
|
||||
@@ -323,7 +323,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
|
||||
$i = 0;
|
||||
while (isset($source[$i]) && '/* */' === substr_replace($source[$i], '', 3, -2)) {
|
||||
$source[$i] = str_replace('*//*', '*/', substr($source[$i], 3, -2));
|
||||
$source[$i] = str_replace('*//* ', '*/', substr($source[$i], 3, -2));
|
||||
++$i;
|
||||
}
|
||||
array_splice($source, $i);
|
||||
|
||||
@@ -142,10 +142,12 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
|
||||
|
||||
$source = "<? /*foo*/ ?>\r\nbar\n";
|
||||
$expected = "/* <? /*foo*//* ?>*/\n/* bar*/\n/* */\n";
|
||||
$source = "<? */*foo*/ ?>\r\nbar\n";
|
||||
$expected = "/* <? *//* *foo*//* ?>*/\n/* bar*/\n/* */\n";
|
||||
$compiled = $twig->compileSource($source, 'index');
|
||||
|
||||
$this->assertContains($expected, $twig->compileSource($source, 'index'));
|
||||
$this->assertContains($expected, $compiled);
|
||||
$this->assertNotContains('/**', $compiled);
|
||||
}
|
||||
|
||||
public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()
|
||||
|
||||
@@ -88,7 +88,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$template = new Twig_TemplateTest(new Twig_Environment($this->getMock('Twig_LoaderInterface')), false);
|
||||
|
||||
$this->assertSame("<? /*bar*/ ?>\n", $template->getSource());
|
||||
$this->assertSame("<? */*bar*/ ?>\n", $template->getSource());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,7 +470,7 @@ class Twig_TemplateTest extends Twig_Template
|
||||
}
|
||||
}
|
||||
}
|
||||
/* <? /*bar*//* ?>*/
|
||||
/* <? *//* *bar*//* ?>*/
|
||||
/* */
|
||||
|
||||
class Twig_TemplateArrayAccessObject implements ArrayAccess
|
||||
|
||||
Reference in New Issue
Block a user