Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Custom Moodle helper collection for mustache. More...
Public Member Functions | |
__construct ($helpers=null, array $blacklistednestedhelpers=[]) | |
Helper Collection constructor. More... | |
add ($name, $helper) | |
Add a helper to this collection. More... | |
strip_blacklisted_helpers ($blacklist, $string) | |
Parse the given string and remove any reference to blacklisted helpers. More... | |
Custom Moodle helper collection for mustache.
core\output\mustache_helper_collection::__construct | ( | $helpers = null , |
|
array | $blacklistednestedhelpers = [] |
||
) |
Helper Collection constructor.
Optionally accepts an array (or Traversable) of $name => $helper
pairs.
Mustache_Exception_InvalidArgumentException | if the $helpers argument isn't an array or Traversable |
array | Traversable | $helpers | (default: null) |
string[] | $blacklistednestedhelpers | Names of helpers that aren't allowed to be called within other helpers. |
core\output\mustache_helper_collection::add | ( | $name, | |
$helper | |||
) |
Add a helper to this collection.
This function has overridden the parent implementation to provide blacklist functionality for certain helpers to prevent them being called from within other helpers. This is because the JavaScript helper can be used in a security exploit if it can be nested.
The function will wrap callable helpers in an anonymous function that strips out the blacklisted helpers from the source string before giving it to the helper function. This prevents the blacklisted helper functions from being called by nested render functions from within other helpers.
string | $name | |
mixed | $helper |
core\output\mustache_helper_collection::strip_blacklisted_helpers | ( | $blacklist, | |
$string | |||
) |
Parse the given string and remove any reference to blacklisted helpers.
E.g. $blacklist = ['js']; $string = "core, move, {{#js}} some nasty JS hack {{/js}}" result: "core, move, {{}}"
string[] | $blacklist | List of helper names to strip |
string | $string | String to parse |
string | Parsed string |