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

When bundling files encoded as UTF-8 with a byte order marker, BOMs are retained #313

Closed
nrkn opened this issue Mar 8, 2013 · 4 comments

Comments

@nrkn
Copy link

nrkn commented Mar 8, 2013

Some UTF-8 encoded files include a byte order marker at the beginning. These are retained when bundling causing a SyntaxError: illegal character error when the script is executed.

Although you're not using fs.readFileSync it's a similar issue to nodejs/node-v0.x-archive#1918

@ForbesLindesay
Copy link
Contributor

👍

@dominictarr
Copy link
Contributor

utf-8 is hard. can you provide a file with such a marker, or a script to add one to a file?

@ForbesLindesay
Copy link
Contributor

This is the code I've used to remove it in the past:

function stripBOM(str){
  return 0xFEFF == str.charCodeAt(0)
    ? str.substring(1)
    : str;
}

This should add one:

function addBOM(str){
  return '\ufeff' + stripBOM(str);
}

@ghost
Copy link

ghost commented Dec 20, 2013

Fixed in 3.11.1 with a test too.

@ghost ghost closed this as completed Dec 20, 2013
npmcomponent pushed a commit to npmcomponent/marcelklehr-changesets that referenced this issue Jan 6, 2014
Browsers dislike \ufeff showing up in the middle of a script, which
happens when we bundle with browserify.  So we remove all BOMs in this
project.

Related: browserify/browserify#313
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants