Handle special characters in error messages when html_errors is Off

Fixes #1538