From 4c0ad1c6304c92d303c7b24ef522ad0cc2ecbfc5 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 93c8a869902b3f..5df33ee5c6fa07 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1532,7 +1532,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(); @@ -1545,10 +1545,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; } } }