Skip to content

buffer.write incorrectly written one more byte in utf16le encoding #26422

Closed
@hkjackey

Description

@hkjackey

Version: v11.10.1, v10.12.0
Platform: Windows 10 (64-bits)
Subsystem: buffer
File Encoding: UTF8

Please consider the following 3 lines of code:
let buf = Buffer.alloc(9);
buf.write('\ud842\udfb7', 1, 'utf16le');
console.log(buf); //<Buffer 00 42 d8 b7 df df 00 00 00>

In this example, only 4 bytes should be written.
However, the last 'df' (the 5th byte) is incorrectly written when the offset is odd number (1,3,5,...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions