Skip to content

Commit 78c45bf

Browse files
committed
MAGETWO-97680: Issue with Email template preview
1 parent 377a6ce commit 78c45bf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,10 @@ protected function getVariable($value, $default = '{no_value_defined}')
367367
}
368368
}
369369
$last = $i;
370-
} elseif (isset($stackVars[$i - 1]['variable']) && $stackVars[$i]['type'] == 'method') {
370+
} elseif (isset($stackVars[$i - 1]['variable'])
371+
&& is_object($stackVars[$i - 1]['variable'])
372+
&& $stackVars[$i]['type'] == 'method'
373+
) {
371374
// Calling object methods
372375
$object = $stackVars[$i - 1]['variable'];
373376
$method = $stackVars[$i]['name'];

lib/internal/Magento/Framework/Filter/Test/Unit/TemplateTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,18 @@ public function testInappropriateCallbacks()
216216
$this->templateFilter->setVariables(['filter' => $this->templateFilter]);
217217
$this->templateFilter->filter('Test {{var filter.addAfterFilterCallback(\'mb_strtolower\')}}');
218218
}
219+
220+
/**
221+
* Check that if calling a method of an object fails expected result is returned.
222+
*
223+
* @return void
224+
*/
225+
public function testInvalidMethodCall()
226+
{
227+
$this->templateFilter->setVariables(['dateTime' => '\DateTime']);
228+
$this->assertEquals(
229+
'\DateTime',
230+
$this->templateFilter->filter('{{var dateTime.createFromFormat(\'d\',\'1548201468\')}}')
231+
);
232+
}
219233
}

0 commit comments

Comments
 (0)