TemplateHelper: improve invalid utf8 handling in hhvm