Skip to content

Commit 6455bea

Browse files
committed
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 c0e3af1 commit 6455bea

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
416416
size_t len,
417417
enum encoding encoding = LATIN1);
418418

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

src/string_bytes.h

Lines changed: 4 additions & 1 deletion
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)