Skip to content

Ignore BOM char #5

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

Merged
merged 2 commits into from
Jan 15, 2020
Merged

Ignore BOM char #5

merged 2 commits into from
Jan 15, 2020

Conversation

Eomm
Copy link
Member

@Eomm Eomm commented Jan 15, 2020

Opening this PR because in some context (eg old proxies) the BOM is appended to the body object sent to a fastify server that will cause an HTTP 500.

With the BOM char the JSON.parse fail, so I would add this check since the Unicode Standard permits the BOM in UTF-8, but is not meaningful in a UTF-8 scenario (like node.js).

The buffer in the test equals to the EF BB EF that the buffer-to-string translates to FEFF (UTF-16 BOM)

A little snippet:

const bom = Buffer.from([239, 187, 191])
console.log(bom.toString().charCodeAt(0))

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 84878f3 into master Jan 15, 2020
@mcollina mcollina deleted the bom branch January 15, 2020 16:14
@Eomm
Copy link
Member Author

Eomm commented Jan 15, 2020

Thank you very much for the release!

@jsumners
Copy link
Member

Latest JSON spec explicitly states that it should be ignored if present. 👍

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

Successfully merging this pull request may close these issues.

3 participants