Skip to content

Commit 364cba6

Browse files
committed
test: pin the single error for a lead surrogate pending at an odd end
The shared utf-16 decoder's end-of-queue step clears the lead byte and the lead surrogate together and returns one error, so a stream ending with both pending yields one U+FFFD, not two. Node 24 (full ICU) agrees on utf-16le [0x00, 0xD8, 0x41].
1 parent 0f45dc8 commit 364cba6

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

TextEncoding/Encoding.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,13 @@ describeEncoding("utf-16le", "TextDecoder utf-16le", function () {
567567
expect(decoder.decode(bytes([0x00, 0xD8, 0x41, 0x00]))).toBe("\uFFFDA");
568568
});
569569

570+
it("emits one U+FFFD when a pending lead surrogate meets a trailing odd byte", function () {
571+
// The decoder's end-of-queue step clears the lead byte and the lead
572+
// surrogate together, as a single error, never two.
573+
expect(decoder.decode(bytes([0x00, 0xD8, 0x41]))).toBe("\uFFFD");
574+
expect(decoder.decode(bytes([0x41, 0x00, 0x00, 0xD8, 0x41]))).toBe("A\uFFFD");
575+
});
576+
570577
it("throws TypeError for an unpaired surrogate when fatal", function () {
571578
var strict = new TextDecoder("utf-16le", { fatal: true });
572579

0 commit comments

Comments
 (0)