Skip to content

Commit

Permalink
fix data url test (#2580)
Browse files Browse the repository at this point in the history
fixup

fixup
  • Loading branch information
KhafraDev committed Jan 3, 2024
1 parent 1ac61d4 commit 5a07f56
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/fetch/dataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand All @@ -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 = {
Expand Down

0 comments on commit 5a07f56

Please sign in to comment.