mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
stream: ensure text() stream consumer flushes correctly
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/39737 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
394c99118d
commit
ca19775d0e
@ -63,6 +63,9 @@ async function text(stream) {
|
||||
else
|
||||
str += dec.decode(chunk, { stream: true });
|
||||
}
|
||||
// Flush the streaming TextDecoder so that any pending
|
||||
// incomplete multibyte characters are handled.
|
||||
str += dec.decode(undefined, { stream: false });
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -232,3 +232,17 @@ const kArrayBuffer =
|
||||
stream.write({});
|
||||
stream.end({});
|
||||
}
|
||||
|
||||
{
|
||||
const stream = new TransformStream();
|
||||
text(stream.readable).then(common.mustCall((str) => {
|
||||
// Incomplete utf8 character is flushed as a replacement char
|
||||
assert.strictEqual(str.charCodeAt(0), 0xfffd);
|
||||
}));
|
||||
const writer = stream.writable.getWriter();
|
||||
Promise.all([
|
||||
writer.write(new Uint8Array([0xe2])),
|
||||
writer.write(new Uint8Array([0x82])),
|
||||
writer.close(),
|
||||
]).then(common.mustCall());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user