From 6f1ce1695a850ef4b4539092b0ac26a529640c65 Mon Sep 17 00:00:00 2001 From: Khafra Date: Tue, 2 Jan 2024 14:32:49 -0500 Subject: [PATCH] fix data url test --- lib/fetch/dataURL.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/fetch/dataURL.js b/lib/fetch/dataURL.js index 12fa1abbb93..fd71d71750f 100644 --- a/lib/fetch/dataURL.js +++ b/lib/fetch/dataURL.js @@ -614,15 +614,6 @@ function removeHTTPWhitespace (str, leading = true, trailing = true) { return i === 0 && j === str.length ? str : str.substring(i, j) } -/** - * @see https://infra.spec.whatwg.org/#ascii-whitespace - * @param {number} char - */ -function isASCIIWhitespace (char) { - // "\r\n\t\f " - return char === 0x00d || char === 0x00a || char === 0x009 || char === 0x00c || char === 0x020 -} - /** * @see https://infra.spec.whatwg.org/#strip-leading-and-trailing-ascii-whitespace * @param {string} str @@ -630,14 +621,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 && isHTTPWhiteSpace(str.charCodeAt(lead))) lead++ } + if (trailing) { - while (j > i && isASCIIWhitespace(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) } module.exports = {