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
Add warning when document encoding may create issues #134
Conversation
Print the following warning if the document encoding may create issues for `buffer`: "The character encoding of the HTML document was not declared as UTF-8. Therefore, the `buffer` package may behave incorrectly in some situations. Consider adding <meta charset="utf-8"> to the <head> section of the HTML document."
It's not so much that Buffer requires the document's character encoding to be utf8, just that the source file encoding matches the document's. |
@jessetane Can you suggest an improved warning message? |
This might be tricky, since I'm not sure it's possible to reliably detect arbitrary encoding mismatches, the test here just happens to work for this particular case... I'll think about it. |
Ok so, there is |
The goal of this package is to mimic the node.js buffer API exactly. So if the encoding is set in a way that will make it work differently than node.js then I think it's fair to warn the user. The question for me is: does the encoding have to be UTF-8, or are there other encodings that are okay? i.e. does the At the very least, it seems that if |
Buffer will function properly as long as no characters that compose its source are misinterpreted due to an encoding mismatch. In #133 the issue was related to the fact that the string literal was misinterpreted, not Buffer itself. Buffer can likely be served safely in a wide range of formats including ones that don't even support Unicode, such as I think in general the rule is just that you just have to know what format your data is in, and if you send that data to anyone else, you must be explicit about it - no exceptions! |
Gotcha. Then it sounds like this check doesn't belong inside this package. |
Yeah, it should be the browser's job, since only it can know for sure that it took a guess at the encoding. Here's what Firefox says if you miss the meta tag / http header:
|
If you are using |
Fixes: #133
Print the following warning if the document encoding may create issues
for
buffer
: