Fix various output sanitisation errors introduced by 1.17.1

The sanitisation step added to the output processing code failed to account for
times when other parts of the application send input that isn't an instance of
the String class.