diff --git a/lib/web/cookies/parse.js b/lib/web/cookies/parse.js index 4ac66dc0974..708be8b1469 100644 --- a/lib/web/cookies/parse.js +++ b/lib/web/cookies/parse.js @@ -4,7 +4,7 @@ const { maxNameValuePairSize, maxAttributeValueSize } = require('./constants') const { isCTLExcludingHtab } = require('./util') const { collectASequenceOfCodePointsFast } = require('../fetch/data-url') const assert = require('node:assert') -const { unescape } = require('node:querystring') +const { unescape: qsUnescape } = require('node:querystring') /** * @description Parses the field-value attributes of a set-cookie header string. @@ -82,7 +82,7 @@ function parseSetCookie (header) { // store arbitrary data in a cookie-value SHOULD encode that data, for // example, using Base64 [RFC4648]. return { - name, value: unescape(value), ...parseUnparsedAttributes(unparsedAttributes) + name, value: qsUnescape(value), ...parseUnparsedAttributes(unparsedAttributes) } } diff --git a/lib/web/fetch/body.js b/lib/web/fetch/body.js index adfcb99302a..73c4b2e317c 100644 --- a/lib/web/fetch/body.js +++ b/lib/web/fetch/body.js @@ -125,7 +125,7 @@ function extractBody (object, keepalive = false) { const prefix = `--${boundary}\r\nContent-Disposition: form-data` /*! formdata-polyfill. MIT License. Jimmy Wärting */ - const escape = (str) => + const formdataEscape = (str) => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22') const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, '\r\n') @@ -143,13 +143,13 @@ function extractBody (object, keepalive = false) { for (const [name, value] of object) { if (typeof value === 'string') { const chunk = textEncoder.encode(prefix + - `; name="${escape(normalizeLinefeeds(name))}"` + + `; name="${formdataEscape(normalizeLinefeeds(name))}"` + `\r\n\r\n${normalizeLinefeeds(value)}\r\n`) blobParts.push(chunk) length += chunk.byteLength } else { - const chunk = textEncoder.encode(`${prefix}; name="${escape(normalizeLinefeeds(name))}"` + - (value.name ? `; filename="${escape(value.name)}"` : '') + '\r\n' + + const chunk = textEncoder.encode(`${prefix}; name="${formdataEscape(normalizeLinefeeds(name))}"` + + (value.name ? `; filename="${formdataEscape(value.name)}"` : '') + '\r\n' + `Content-Type: ${ value.type || 'application/octet-stream' }\r\n\r\n`)