From 5a07f562c7e7ddbe669a3d203dca001ba447bfbb Mon Sep 17 00:00:00 2001 From: Khafra Date: Tue, 2 Jan 2024 21:17:29 -0500 Subject: [PATCH] fix data url test (#2580) fixup fixup --- lib/fetch/dataURL.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/fetch/dataURL.js b/lib/fetch/dataURL.js index 12fa1abbb93..d7a638866a3 100644 --- a/lib/fetch/dataURL.js +++ b/lib/fetch/dataURL.js @@ -604,14 +604,18 @@ function isHTTPWhiteSpace (char) { * @param {boolean} [trailing=true] */ function removeHTTPWhitespace (str, leading = true, trailing = true) { - let i = 0; let j = str.length + let lead = 0 + let trail = str.length - 1 + if (leading) { - while (j > i && isHTTPWhiteSpace(str.charCodeAt(i))) --i + while (lead < str.length && isHTTPWhiteSpace(str.charCodeAt(lead))) lead++ } + if (trailing) { - while (j > i && isHTTPWhiteSpace(str.charCodeAt(j - 1))) --j + while (trail > 0 && isHTTPWhiteSpace(str.charCodeAt(trail))) trail-- } - return i === 0 && j === str.length ? str : str.substring(i, j) + + return lead === 0 && trail === str.length - 1 ? str : str.slice(lead, trail + 1) } /** @@ -630,14 +634,18 @@ function isASCIIWhitespace (char) { * @param {boolean} [trailing=true] */ function removeASCIIWhitespace (str, leading = true, trailing = true) { - let i = 0; let j = str.length + let lead = 0 + let trail = str.length - 1 + if (leading) { - while (j > i && isASCIIWhitespace(str.charCodeAt(i))) --i + while (lead < str.length && isASCIIWhitespace(str.charCodeAt(lead))) lead++ } + if (trailing) { - while (j > i && isASCIIWhitespace(str.charCodeAt(j - 1))) --j + while (trail > 0 && isASCIIWhitespace(str.charCodeAt(trail))) trail-- } - return i === 0 && j === str.length ? str : str.substring(i, j) + + return lead === 0 && trail === str.length - 1 ? str : str.slice(lead, trail + 1) } module.exports = {