Fixes #5200 Handle template contents with unicode strings better