diegoles / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

closurebuilder "script" output mode and windows - Remove BOM from files #408

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. Create some source files with UTF8 + BOM (Visual Studio for instance adds 
the BOM by default)
2. Run closurebuilder to generate a single script file (outputmode=script)
3. The generated file does not load in browsers as it has illegal characters

What is the expected output? What do you see instead?
The generated file does not load in browsers as it has illegal characters

What version of the product are you using? On what operating system?
Latest

Please provide any additional information below.

Attached, fixes this by removing BOM characters if they exist.  Note: Only 
tested on my Win7 machine but it looks pretty safe

Original issue reported on code.google.com by guido.tapia@gmail.com on 3 Jan 2012 at 3:32

Attachments:

GoogleCodeExporter commented 8 years ago
So what if I have code that's like

if (x == 'bom char')

where the bom char is encoded as utf8 -- then this will just remove it, no?

You should only ever remove it if it is the very first char in the file, and 
only if the input encoding is utf8. (Although it's difficult to imagine this 
sequence of bytes being a valid beginning of a file in any other encoding.)

Might be better to handle this directly in closure compiler since it has all 
the encoding information at its disposal.

Original comment by ibmirkin@gmail.com on 3 Jan 2012 at 4:50

GoogleCodeExporter commented 8 years ago
Absolutely correct, my apologies attached checks for startswith and just 
replaces those 3 characters.

It may be more elegant to do proper encoding check but I'm unfortunately 
alergic to python so this is my hack.

Also we cannot use the compiler to do this as running output_mode=script does 
not compile.

Original comment by guido.tapia@gmail.com on 3 Jan 2012 at 5:08

Attachments:

GoogleCodeExporter commented 8 years ago
assigning to self, will investigate

Original comment by nn...@google.com on 11 May 2012 at 7:47