Skip to content

Commit a9e69f7

Browse files
author
Oleksandr Gorkun
committed
MC-11058: Empty results when using methods in templates
1 parent 2f30dde commit a9e69f7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ protected function getVariable($value, $default = '{no_value_defined}')
412412
}
413413
}
414414
$last = $i;
415-
} elseif (isset($stackVars[$i - 1]['variable']) && $stackVars[$i]['type'] == 'method') {
415+
} elseif (isset($stackVars[$i - 1]['variable'])
416+
&& is_object($stackVars[$i - 1]['variable'])
417+
&& $stackVars[$i]['type'] == 'method'
418+
) {
416419
// Calling object methods
417420
if (method_exists($stackVars[$i - 1]['variable'], $stackVars[$i]['name'])) {
418421
$stackVars[$i]['args'] = $this->getStackArgs($stackVars[$i]['args']);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,16 @@ private function getObjectData()
380380
$dataObject->setAllVisibleItems($visibleItems);
381381
return $dataObject;
382382
}
383+
384+
/**
385+
* Check that if calling a method of an object fails expected result is returned.
386+
*/
387+
public function testInvalidMethodCall()
388+
{
389+
$this->templateFilter->setVariables(['dateTime' => '\DateTime']);
390+
$this->assertEquals(
391+
'\DateTime',
392+
$this->templateFilter->filter('{{var dateTime.createFromFormat(\'d\',\'1548201468\')}}')
393+
);
394+
}
383395
}

0 commit comments

Comments
 (0)