We've managed to find a bug ~ set back with the HTML purify library. It would appear currently there are alot of checks that are broken after cleaning has occurred (PARAM_TEXT or PARAM_CLEAN).
The problem appears to be that HTMLPurify is normalising line breaks in text to \n causing the comparisons to break as many clients send \r\n.
I've been talking to Martin and Jerome about it and the general feeling seems to be that it would wonderful to normalise all text in Moodle but the task would be too huge to be worth tackling.
We've had a quick look at the HTMLPurify library and come up with a small hack that resolves the problem by sorting it so that HTMLPurify doesn't normalise the text or replace line breaks with the system preferred after cleaning.
I've attached a patch to illustrate what we found to work.
Keen to see what you think on this one!