Skip to content

Commit a009faa

Browse files
committed
MC-22982: Enable template filter strict mode by default
1 parent 3811867 commit a009faa

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

dev/tests/integration/testsuite/Magento/Framework/Filter/TemplateTest.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public function testIfDirective()
155155

156156
public function testNonDataObjectVariableParsing()
157157
{
158+
$previous = $this->templateFilter->setStrictMode(false);
158159
$this->templateFilter->setVariables(
159160
[
160161
'address' => new class {
@@ -168,11 +169,33 @@ public function format($type)
168169

169170
$template = '{{var address.format(\'html\')}}';
170171
$expected = '<foo>html</foo>';
171-
self::assertEquals($expected, $this->templateFilter->filter($template));
172+
try {
173+
self::assertEquals($expected, $this->templateFilter->filter($template));
174+
} finally {
175+
$this->templateFilter->setStrictMode($previous);
176+
}
177+
}
178+
179+
public function testStrictModeByDefault()
180+
{
181+
$this->templateFilter->setVariables(
182+
[
183+
'address' => new class {
184+
public function format()
185+
{
186+
throw new \Exception('Should not run');
187+
}
188+
}
189+
]
190+
);
191+
192+
$template = '{{var address.format(\'html\')}}';
193+
self::assertEquals('', $this->templateFilter->filter($template));
172194
}
173195

174196
public function testComplexVariableArguments()
175197
{
198+
$previous = $this->templateFilter->setStrictMode(false);
176199
$this->templateFilter->setVariables(
177200
[
178201
'address' => new class {
@@ -187,11 +210,16 @@ public function format($a, $b, $c)
187210

188211
$template = '{{var address.format($arg1,\'bar\',[param1:baz])}}';
189212
$expected = 'foo bar baz';
190-
self::assertEquals($expected, $this->templateFilter->filter($template));
213+
try {
214+
self::assertEquals($expected, $this->templateFilter->filter($template));
215+
} finally {
216+
$this->templateFilter->setStrictMode($previous);
217+
}
191218
}
192219

193220
public function testComplexVariableGetterArguments()
194221
{
222+
$previous = $this->templateFilter->setStrictMode(false);
195223
$this->templateFilter->setVariables(
196224
[
197225
'address' => new class extends DataObject {
@@ -206,7 +234,11 @@ public function getFoo($a, $b, $c)
206234

207235
$template = '{{var address.getFoo($arg1,\'bar\',[param1:baz])}}';
208236
$expected = 'foo bar baz';
209-
self::assertEquals($expected, $this->templateFilter->filter($template));
237+
try {
238+
self::assertEquals($expected, $this->templateFilter->filter($template));
239+
} finally {
240+
$this->templateFilter->setStrictMode($previous);
241+
}
210242
}
211243

212244
public function testNonDataObjectRendersBlankInStrictMode()

lib/internal/Magento/Framework/Filter/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Template implements \Zend_Filter_Interface
9191
/**
9292
* @var bool
9393
*/
94-
private $strictMode = false;
94+
private $strictMode = true;
9595

9696
/**
9797
* @var VariableResolverInterface|null

0 commit comments

Comments
 (0)