diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-08-31 16:52:44 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-09-03 22:32:06 +0200 |
commit | 6455bea52ba262cea8d1c706ec8a2eec192ec643 (patch) | |
tree | 20ba2e0dc78a8a1a8037e7b114141a2051eb4678 | |
parent | c0e3af1bf25604b7c950fd4cafb3aacaf1f5eaa0 (diff) | |
download | node-new-6455bea52ba262cea8d1c706ec8a2eec192ec643.tar.gz |
src: warn about odd UTF-16 decoding function signature
Using a `uint16_t` sequence for UTF-16 processing would typically
imply that the sequence already contains the correct 16-bit
code units.
However, our API does not account for that. The previous comments
were somewhat misleading, since endianness is typically applied to
sequences of bytes, which is not something that this API works with.
PR-URL: https://github.com/nodejs/node/pull/22623
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r-- | src/node.h | 3 | ||||
-rw-r--r-- | src/string_bytes.h | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/node.h b/src/node.h index 8433eed374..1154c39765 100644 --- a/src/node.h +++ b/src/node.h @@ -416,7 +416,8 @@ NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate, size_t len, enum encoding encoding = LATIN1); -// The input buffer should be in host endianness. +// Warning: This reverses endianness on Big Endian platforms, even though the +// signature using uint16_t implies that it should not. NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate, const uint16_t* buf, size_t len); diff --git a/src/string_bytes.h b/src/string_bytes.h index 8280e37987..9e64fa0ee5 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -97,7 +97,10 @@ class StringBytes { enum encoding encoding, v8::Local<v8::Value>* error); - // The input buffer should be in host endianness. + // Warning: This reverses endianness on BE platforms, even though the + // signature using uint16_t implies that it should not. + // However, the brokenness is already public API and can't therefore + // be changed easily. static v8::MaybeLocal<v8::Value> Encode(v8::Isolate* isolate, const uint16_t* buf, size_t buflen, |