Use proper encoding on compat_str construction when necessary