UTF-8 with BOM encoded scripts fail #1440

Closed
diversario opened this Issue Aug 2, 2011 · 5 comments

4 participants

@diversario

If you try to run a UTF-8 with BOM encoded script like

#!/usr/bin/env node

console.log("UTF8!");

it fails with

./test.js: 1: #!/usr/bin/env: not found
./test.js: 3: Syntax error: word unexpected (expecting ")")

if run as executable script or

test.js:1
#!/usr/bin/env
 ^

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
SyntaxError: Unexpected token ILLEGAL

if given to node.
Scripts encoded in ANSI or UTF-8 without BOM work fine.

@bnoordhuis bnoordhuis added a commit to bnoordhuis/node that referenced this issue Aug 2, 2011
@bnoordhuis bnoordhuis module: strip byte order marker when loading *.js and *.json files
BOMs make V8 raise a 'SyntaxError: Unexpected token ILLEGAL' exception.

Fixes #1440.
24d4539
@bnoordhuis
Node.js Foundation member

@isaacs: can you review 24d4539?

@isaacs

@bnoordhuis The code LGTM, but I can't actually get the tests to fail without the code change. Is git "fixing" the BOM byte or something?

@bnoordhuis
Node.js Foundation member

The BOM is in the repo:

$ curl -s https://raw.github.com/joyent/node/24d4539/test/fixtures/utf8-bom.json | xxd
0000000: efbb bf34 320a                           ...42.

Do you have locale settings configured in your ~/.gitconfig or .git/config?

@koichik

In my environment, test-module-loading.js failed as expected before build.

@bnoordhuis bnoordhuis added a commit that closed this issue Aug 4, 2011
@bnoordhuis bnoordhuis module: strip byte order marker when loading *.js and *.json files
BOMs make V8 raise a 'SyntaxError: Unexpected token ILLEGAL' exception.

Fixes #1440.
ac722bb
@bnoordhuis bnoordhuis closed this in ac722bb Aug 4, 2011
@bnoordhuis
Node.js Foundation member

Thanks, @koichik. Merged in ac722bb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment