diff --git a/src/node_i18n.cc b/src/node_i18n.cc index bab06cfcdfc41a..a98fdca4d1bffd 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -179,7 +179,7 @@ MaybeLocal TranscodeToUcs2(Isolate* isolate, MaybeLocal ret; MaybeStackBuffer destbuf(source_length); Converter from(fromEncoding); - const size_t length_in_chars = source_length * sizeof(*destbuf); + const size_t length_in_chars = source_length * sizeof(UChar); ucnv_toUChars(from.conv, *destbuf, length_in_chars, source, source_length, status); if (U_SUCCESS(*status)) diff --git a/test/parallel/test-icu-transcode.js b/test/parallel/test-icu-transcode.js index f45b9974367af3..2cdd4078a2cceb 100644 --- a/test/parallel/test-icu-transcode.js +++ b/test/parallel/test-icu-transcode.js @@ -46,3 +46,13 @@ assert.throws( () => buffer.transcode(Buffer.from('a'), 'uf8', 'b'), /Unable to transcode Buffer \[U_ILLEGAL_ARGUMENT_ERROR\]/ ); + +assert.deepStrictEqual( + buffer.transcode(Buffer.from('hi', 'ascii'), 'ascii', 'utf16le'), + Buffer.from('hi', 'utf16le')); +assert.deepStrictEqual( + buffer.transcode(Buffer.from('hi', 'latin1'), 'latin1', 'utf16le'), + Buffer.from('hi', 'utf16le')); +assert.deepStrictEqual( + buffer.transcode(Buffer.from('hä', 'latin1'), 'latin1', 'utf16le'), + Buffer.from('hä', 'utf16le'));