-
Notifications
You must be signed in to change notification settings - Fork 536
Buffer#toString throw on unsupported encodings #2418
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
base: v2-maintenance
Are you sure you want to change the base?
Buffer#toString throw on unsupported encodings #2418
Conversation
77364be to
d2c84fe
Compare
|
The core logic has been factored out since both For the case insensitive matching, raw bit-ops are preferred since the Both |
|
Thanks for the revisions 👍 |
| for (i = 0; i < DUK_BUFFER_ENCODING_MAX_LEN; ++i) { | ||
| if (encoding[i] == 0) { buf[i] = 0; break; } | ||
| buf[i] = (char) (encoding[i] | 0x20); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop works incorrectly if i reaches the maximum encoding length without finding a NUL terminator in the input: buf will remain unterminated and it's used for a strcmp() later.
Inputs like utf8\u0000bar are (technically) handled incorrectly, as the loop will terminate on the NUL.
ORing 0x20 on all input chars also results in some incorrect inputs accepted, e.g. "utf\u000d8" will be accepted because 0x0d | 0x20 = 0x2d which is '-'.
So overall I don't think approach is easy to make work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it'd produce less code to just short circuit compare the input, e.g.:
if ((p[0] | 0x20) == 'u' && (p[1] | 0x20) == 't' && (p[2] | 0x20) == 'f') {
if (p[3] == '8' && encoding_len == 4) {
/* utf8 */
} else if (p[3] == '-' && p[4] == '8' && encoding_len == 5) {
/* utf8 */
}
}
/* invalid */
|
I'm merging the clang-format indent changes to master and to v2-maintenance. Once that's done, the easiest approach is probably to clang-format your changed files first, and then rebase against master/v2-maintenance. This should keep the diff minimal and avoid conflicts. |
|
Ok, clang-format changes are now in master and v2-maintenance. To reindent code: |
b93df51 to
a9b65f7
Compare
Fixes #2417
New behavior: if argument is not undefined/unspecified or
"utf8", throw an error.Note:
nullis not a supported encoding in NodeJS