Skip to content

Commit 156a5ec

Browse files
authored
chore: avoid overriding global escape (#4437)
1 parent d2fce20 commit 156a5ec

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/web/cookies/parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { maxNameValuePairSize, maxAttributeValueSize } = require('./constants')
44
const { isCTLExcludingHtab } = require('./util')
55
const { collectASequenceOfCodePointsFast } = require('../fetch/data-url')
66
const assert = require('node:assert')
7-
const { unescape } = require('node:querystring')
7+
const { unescape: qsUnescape } = require('node:querystring')
88

99
/**
1010
* @description Parses the field-value attributes of a set-cookie header string.
@@ -82,7 +82,7 @@ function parseSetCookie (header) {
8282
// store arbitrary data in a cookie-value SHOULD encode that data, for
8383
// example, using Base64 [RFC4648].
8484
return {
85-
name, value: unescape(value), ...parseUnparsedAttributes(unparsedAttributes)
85+
name, value: qsUnescape(value), ...parseUnparsedAttributes(unparsedAttributes)
8686
}
8787
}
8888

lib/web/fetch/body.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function extractBody (object, keepalive = false) {
125125
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
126126

127127
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
128-
const escape = (str) =>
128+
const formdataEscape = (str) =>
129129
str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22')
130130
const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, '\r\n')
131131

@@ -143,13 +143,13 @@ function extractBody (object, keepalive = false) {
143143
for (const [name, value] of object) {
144144
if (typeof value === 'string') {
145145
const chunk = textEncoder.encode(prefix +
146-
`; name="${escape(normalizeLinefeeds(name))}"` +
146+
`; name="${formdataEscape(normalizeLinefeeds(name))}"` +
147147
`\r\n\r\n${normalizeLinefeeds(value)}\r\n`)
148148
blobParts.push(chunk)
149149
length += chunk.byteLength
150150
} else {
151-
const chunk = textEncoder.encode(`${prefix}; name="${escape(normalizeLinefeeds(name))}"` +
152-
(value.name ? `; filename="${escape(value.name)}"` : '') + '\r\n' +
151+
const chunk = textEncoder.encode(`${prefix}; name="${formdataEscape(normalizeLinefeeds(name))}"` +
152+
(value.name ? `; filename="${formdataEscape(value.name)}"` : '') + '\r\n' +
153153
`Content-Type: ${
154154
value.type || 'application/octet-stream'
155155
}\r\n\r\n`)

0 commit comments

Comments
 (0)