Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken international characters: the file is written as UTF-8 and read as ANSI by Visual Studio #178

Closed
jotabe-net opened this issue Apr 26, 2017 · 0 comments

Comments

@jotabe-net
Copy link
Contributor

jotabe-net commented Apr 26, 2017

If I use special characters in my code, like an accented u: ú, when the templates are rendered, and I open them in Visual Studio, the special characters doesn't look as expected. In this example ú appears where I should see the ú.

I've opened the file with Notepad++, and it detects is an UTF-8 file, and I see the special character as expected. If I try to see it as ANSI, I get the same result as in VS.

If I use Notepad++ to convert the file to ANSI, and see it in Visual Studio, it looks fine.

In this VS documentation page I can see:

By default, Visual Studio detects a byte-order mark to determine if the source file is in an encoded Unicode format, for example, UTF-16 or UTF-8. If no byte-order mark is found, it assumes the source file is encoded using the current user code page, unless you have specified a code page by using /utf-8 or the /source-charset option.

It looks like the problem is in the SaveMethod of src/Typewriter/Generation/Template.cs, which invokes File.WriteAllText. According to the remarks in the documentation:

This method uses UTF-8 encoding without a Byte-Order Mark (BOM)

If you keep reading, you'll see this:

If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the WriteAllText(String, String, Encoding) method overload with UTF8 encoding.

Saving it as UTF8 is a good idea beacuse by default tsc expects the files to be encoded as UTF8(see --charset in https://www.typescriptlang.org/docs/handbook/compiler-options.html)

@frhagn frhagn closed this as completed in c391709 Jul 24, 2017
frhagn added a commit that referenced this issue Jul 24, 2017
Fixes #178 by writing UTF8 BOM in generated files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant