Deal with invalid encodings in template variables.