This project is read-only.


Encoding not preserved during compression


When compressing a JavaScript file containing accented French characters, the characters are being corrupted in the output even after specifying the proper encoding (e.g. Windows-1252). For example, the string "Frédéric François" would appear as "Fr?d?ric Fran?ois" in the output.
I've taken a look through the source code and the reason for this issue is in the JavaScriptCompressor constructor (in Model\JavaScriptCompressor.cs). The passed encoding is being used to construct the MemoryStream, but the StreamReader used to read the new MemoryStream does not have the encoding specified and so it reverts back to using Encoding.Default. The encoding needs to be passed to the StreamReader constructor as well. The line:
_tokens = Parse(new StreamReader(memoryStream), ErrorReporter);
Should become:
_tokens = Parse(new StreamReader(memoryStream, encoding), ErrorReporter);
I've tested this for my application and adding this parameter resolves the problem. You can do a small test of this with the following JavaScript code:
alert("Frédéric François");
If you need any more information please let me know.
Closed Sep 21, 2011 at 1:38 AM by purekrome
  • Fixed. Updated to release which is now available via NuGet.