From 4fa8a62b909ebc0e9423f644a56b67cede13dd09 Mon Sep 17 00:00:00 2001 From: Khafra Date: Tue, 2 Jan 2024 14:32:49 -0500 Subject: [PATCH] fix data url test fixup --- lib/fetch/dataURL.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/fetch/dataURL.js b/lib/fetch/dataURL.js index 12fa1abbb93..3cae5555a68 100644 --- a/lib/fetch/dataURL.js +++ b/lib/fetch/dataURL.js @@ -630,14 +630,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 = {