Skip to content

Commit f064d44

Browse files
addaleaxtargos
authored andcommitted
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: #22623 Reviewed-By: Colin Ihrig <[email protected]>
1 parent 696f7a5 commit f064d44

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/node.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
424424
size_t len,
425425
enum encoding encoding = LATIN1);
426426

427-
// The input buffer should be in host endianness.
427+
// Warning: This reverses endianness on Big Endian platforms, even though the
428+
// signature using uint16_t implies that it should not.
428429
NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
429430
const uint16_t* buf,
430431
size_t len);

src/string_bytes.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ class StringBytes {
9797
enum encoding encoding,
9898
v8::Local<v8::Value>* error);
9999

100-
// The input buffer should be in host endianness.
100+
// Warning: This reverses endianness on BE platforms, even though the
101+
// signature using uint16_t implies that it should not.
102+
// However, the brokenness is already public API and can't therefore
103+
// be changed easily.
101104
static v8::MaybeLocal<v8::Value> Encode(v8::Isolate* isolate,
102105
const uint16_t* buf,
103106
size_t buflen,

0 commit comments

Comments
 (0)