When using the lib/moodlelib.php function optional_param() with PARAM_CLEAN (or PARAM_TEXT) to clean input parameters, unexpected and unwanted effects may be caused if the HTML purifier is enabled ($CFG->enablehtmlpurifier).
This seems to be because optional_param() in turn calls clean_param(), which itself calls clean_text() (in lib/weblib.php). The default $format parameter in clean_text() is FORMAT_MOODLE, and clean_param() does not specify any alternative.
The problem shows up if, for example, a parameter with an ampersand in its value is read in using optional_param() with the PARAM_CLEAN setting. For example, "This & that". With the HTML Purifier enabled, this gets returned from optional_param() as "This & that". That might be fine if the value were intended to be displayed, but this is input, so is more likely to be used for other purposes; for example, a database search.
A workaround for this is to use PARAM_RAW or PARAM_NOTAGS for text input that might potentially not work if mangled with HTML entities, but there is potential for this to cause unintended problems if, say, a plugin is developed using PARAM_CLEAN without the HTML Purifier on, and then deployed in a Moodle that does have it on.
Example output of attached script:
With HTML purifier off, $value matches $expected
With HTML purifier on, $value (This & that) does not match $expected (This & that)