From d77db883869b3ddb4565c6895261da852d3474be Mon Sep 17 00:00:00 2001 From: Xuguang Mei Date: Tue, 15 Feb 2022 19:01:36 +0800 Subject: [PATCH] doc: fix bug in `readable.unshift` code example PR-URL: https://github.com/nodejs/node/pull/41944 Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Mestery Reviewed-By: Luigi Pinca --- doc/api/stream.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 0297af92600654..3d701b1b0b625f 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1528,7 +1528,7 @@ function parseHeader(stream, callback) { let chunk; while (null !== (chunk = stream.read())) { const str = decoder.write(chunk); - if (str.match(/\n\n/)) { + if (str.includes('\n\n')) { // Found the header boundary. const split = str.split(/\n\n/); header += split.shift(); @@ -1541,10 +1541,10 @@ function parseHeader(stream, callback) { stream.unshift(buf); // Now the body of the message can be read from the stream. callback(null, header, stream); - } else { - // Still reading the header. - header += str; + return; } + // Still reading the header. + header += str; } } }