mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 12:37:15 +00:00
Merge branch '2.x' into 3.x
* 2.x: Fix custom escapers when using multiple Twig environments Rename variable
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 3.3.9 (2022-XX-XX)
|
||||
|
||||
* n/a
|
||||
* Fix custom escapers when using multiple Twig environments
|
||||
|
||||
# 3.3.8 (2022-02-04)
|
||||
|
||||
|
||||
@@ -387,13 +387,8 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
return rawurlencode($string);
|
||||
|
||||
default:
|
||||
static $escapers;
|
||||
|
||||
if (null === $escapers) {
|
||||
$escapers = $env->getExtension(EscaperExtension::class)->getEscapers();
|
||||
}
|
||||
|
||||
if (isset($escapers[$strategy])) {
|
||||
$escapers = $env->getExtension(EscaperExtension::class)->getEscapers();
|
||||
if (array_key_exists($strategy, $escapers)) {
|
||||
return $escapers[$strategy]($env, $string, $charset);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,11 +91,11 @@ final class SandboxExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function checkPropertyAllowed($obj, $method, int $lineno = -1, Source $source = null): void
|
||||
public function checkPropertyAllowed($obj, $property, int $lineno = -1, Source $source = null): void
|
||||
{
|
||||
if ($this->isSandboxed()) {
|
||||
try {
|
||||
$this->policy->checkPropertyAllowed($obj, $method);
|
||||
$this->policy->checkPropertyAllowed($obj, $property);
|
||||
} catch (SecurityNotAllowedPropertyError $e) {
|
||||
$e->setSourceContext($source);
|
||||
$e->setTemplateLine($lineno);
|
||||
|
||||
@@ -31,5 +31,5 @@ interface SecurityPolicyInterface
|
||||
/**
|
||||
* @throws SecurityNotAllowedPropertyError
|
||||
*/
|
||||
public function checkPropertyAllowed($obj, $method): void;
|
||||
public function checkPropertyAllowed($obj, $property): void;
|
||||
}
|
||||
|
||||
@@ -355,6 +355,13 @@ class Twig_Tests_Extension_EscaperTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testUnknownCustomEscaper()
|
||||
{
|
||||
$this->expectException(RuntimeError::class);
|
||||
|
||||
twig_escape_filter(new Environment($this->createMock(LoaderInterface::class)), 'foo', 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideCustomEscaperCases
|
||||
*/
|
||||
@@ -375,11 +382,15 @@ class Twig_Tests_Extension_EscaperTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testUnknownCustomEscaper()
|
||||
public function testCustomEscapersOnMultipleEnvs()
|
||||
{
|
||||
$this->expectException(RuntimeError::class);
|
||||
$env1 = new Environment($this->createMock(LoaderInterface::class));
|
||||
$env1->getExtension(EscaperExtension::class)->setEscaper('foo', 'Twig\Tests\foo_escaper_for_test');
|
||||
$env2 = new Environment($this->createMock(LoaderInterface::class));
|
||||
$env2->getExtension(EscaperExtension::class)->setEscaper('foo', 'Twig\Tests\foo_escaper_for_test1');
|
||||
|
||||
twig_escape_filter(new Environment($this->createMock(LoaderInterface::class)), 'foo', 'bar');
|
||||
$this->assertSame('fooUTF-8', twig_escape_filter($env1, 'foo', 'foo'));
|
||||
$this->assertSame('fooUTF-81', twig_escape_filter($env2, 'foo', 'foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,6 +421,11 @@ function foo_escaper_for_test(Environment $twig, $string, $charset)
|
||||
return $string.$charset;
|
||||
}
|
||||
|
||||
function foo_escaper_for_test1(Environment $twig, $string, $charset)
|
||||
{
|
||||
return $string.$charset.'1';
|
||||
}
|
||||
|
||||
interface Extension_SafeHtmlInterface
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user