Fix substitution of invalid UTF8 sequences in htmlspecialchars.

This fixes #2679