moodle-tool_trigger
moodle-tool_trigger copied to clipboard
Make URL encode of variables explict per instance
Current all HTTP Post variables are URL encoded, this is not always helpful. Sometimes we don't want to URL encode values, and sometimes we only want to encode some values.
I suggest making a prefix on a value to indicate if it should be url encoded. So: {urlencode:username}
will be encoded but {username}
won't be
The code that does the {placeholder}
replacement stuff is in classes/helper/datafield_manager.php
Right now it finds placeholders by searching for the regex /\{([-_A-Za-z0-9]+)\}/u
. You'll need to add :
to that, and maybe also capture the "function" part before the :
separately. So something like something like /\{(?:(?P<func>[_A-Za-z0-9]+):)?(?P<datafield>[-_A-Za-z0-9]+)\}/u
.
As discussed on chat, it might also be a good idea to change the syntax from {placeholder}
to %placeholder%
or #placeholder#
, in order to reduce the conflict with JSON syntax. Particularly if we're going to be adding colons inside the {}
. Although I suppose we could use something else instead, like |
or even just a space: {urlencode user_username}
.