You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Platform and Target: Apache, MySQL, Windows 10, PHP 7
What you did
Created a helper that uses the StringTemplateTrait.
class MyHelper extends Helper {
use StringTemplateTrait;
protected $_defaultConfig = [
'templates' => [
'Bar' => 'hello'
]
];
public function Foo() {
return $this->formatTemplate('Oops',[]);
}
}
The template Oops does not exist.
Some where else like a view
<?= $this->My->Foo()." world" ?>
The view still renders without error. No warning is given to the developer that the output is not as expected.
Expected Behavior
Should trigger an error that the template Oops does not exist.
Actual Behavior
The Foo() method returns null which mutates into an empty string. The rendered output for the view is world, but the expected output hello world is not generated.
I experienced this as a security bug in my app. The JavaScript code that was suppose to be injected into the view was from a template, but the name has a spelling mistake. The output for the view mutated the null into an empty string. This resulted in valid JavaScript code that was missing an important chunk from the template.
The text was updated successfully, but these errors were encountered:
StringTemplate didn't raise exceptions on purpose to make it more tolerant of programmer error. However, you raise a good point that we should be helping developers find their mistakes.
Missing templates are a signal that a developer has made a mistake.
We should help them find this error and an exception is the simplest way
to signal an error to the developer.
Refs #8554
Missing templates are a signal that a developer has made a mistake.
We should help them find this error and an exception is the simplest way
to signal an error to the developer.
Refs #8554
This is a (multiple allowed):
What you did
Created a helper that uses the
StringTemplateTrait
.The template
Oops
does not exist.Some where else like a view
The view still renders without error. No warning is given to the developer that the output is not as expected.
Expected Behavior
Should trigger an error that the template
Oops
does not exist.Actual Behavior
The
Foo()
method returnsnull
which mutates into an empty string. The rendered output for the view isworld
, but the expected outputhello world
is not generated.I experienced this as a security bug in my app. The JavaScript code that was suppose to be injected into the view was from a template, but the name has a spelling mistake. The output for the view mutated the
null
into an empty string. This resulted in valid JavaScript code that was missing an important chunk from the template.The text was updated successfully, but these errors were encountered: