Skip to content

Commit bcfe21d

Browse files
nodejs-github-botRafaelGSS
authored andcommitted
deps: update undici to 7.29.0
PR-URL: #64713 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent 05f541b commit bcfe21d

16 files changed

Lines changed: 1199 additions & 435 deletions

File tree

deps/undici/src/lib/cache/memory-cache-store.js

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,62 @@ class MemoryCacheStore extends EventEmitter {
218218
}
219219

220220
function findEntry (key, entries, now) {
221-
return entries.find((entry) => (
222-
entry.deleteAt > now &&
223-
entry.method === key.method &&
224-
(entry.vary == null || Object.keys(entry.vary).every(headerName => {
225-
if (entry.vary[headerName] === null) {
226-
return key.headers[headerName] === undefined
221+
for (let i = 0; i < entries.length; i++) {
222+
const entry = entries[i]
223+
if (
224+
entry.deleteAt > now &&
225+
entry.method === key.method &&
226+
varyMatches(key, entry)
227+
) {
228+
return entry
229+
}
230+
}
231+
}
232+
233+
function varyMatches (key, entry) {
234+
if (entry.vary == null) {
235+
return true
236+
}
237+
238+
for (const headerName in entry.vary) {
239+
if (Object.hasOwn(entry.vary, headerName) && !headerValueEquals(key.headers?.[headerName], entry.vary[headerName])) {
240+
return false
241+
}
242+
}
243+
244+
return true
245+
}
246+
247+
/**
248+
* @param {string|string[]|null|undefined} lhs
249+
* @param {string|string[]|null|undefined} rhs
250+
* @returns {boolean}
251+
*/
252+
function headerValueEquals (lhs, rhs) {
253+
if (lhs == null && rhs == null) {
254+
return true
255+
}
256+
257+
if ((lhs == null && rhs != null) ||
258+
(lhs != null && rhs == null)) {
259+
return false
260+
}
261+
262+
if (Array.isArray(lhs) && Array.isArray(rhs)) {
263+
if (lhs.length !== rhs.length) {
264+
return false
265+
}
266+
267+
for (let i = 0; i < lhs.length; i++) {
268+
if (lhs[i] !== rhs[i]) {
269+
return false
227270
}
271+
}
272+
273+
return true
274+
}
228275

229-
return entry.vary[headerName] === key.headers[headerName]
230-
}))
231-
))
276+
return lhs === rhs
232277
}
233278

234279
module.exports = MemoryCacheStore

deps/undici/src/lib/cache/sqlite-cache-store.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,13 @@ function headerValueEquals (lhs, rhs) {
454454
return false
455455
}
456456

457-
return lhs.every((x, i) => x === rhs[i])
457+
for (let i = 0; i < lhs.length; i++) {
458+
if (lhs[i] !== rhs[i]) {
459+
return false
460+
}
461+
}
462+
463+
return true
458464
}
459465

460466
return lhs === rhs

deps/undici/src/lib/core/request.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,13 @@ function processHeader (request, key, val) {
390390
} else if (typeof val[i] === 'object') {
391391
throw new InvalidArgumentError(`invalid ${key} header`)
392392
} else {
393-
arr.push(`${val[i]}`)
393+
// Coerce primitives (and reject unsafe coercions such as functions
394+
// with a crafted toString/Symbol.toPrimitive).
395+
const str = `${val[i]}`
396+
if (!isValidHeaderValue(str)) {
397+
throw new InvalidArgumentError(`invalid ${key} header`)
398+
}
399+
arr.push(str)
394400
}
395401
}
396402
val = arr
@@ -401,7 +407,12 @@ function processHeader (request, key, val) {
401407
} else if (val === null) {
402408
val = ''
403409
} else {
410+
// Coerce primitives (and reject unsafe coercions such as functions
411+
// with a crafted toString/Symbol.toPrimitive).
404412
val = `${val}`
413+
if (!isValidHeaderValue(val)) {
414+
throw new InvalidArgumentError(`invalid ${key} header`)
415+
}
405416
}
406417

407418
if (headerName === 'host') {

deps/undici/src/lib/dispatcher/client-h1.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
RequestContentLengthMismatchError,
1111
ResponseContentLengthMismatchError,
1212
RequestAbortedError,
13+
InvalidArgumentError,
1314
HeadersTimeoutError,
1415
HeadersOverflowError,
1516
SocketError,
@@ -1134,8 +1135,16 @@ function writeH1 (client, request) {
11341135
}
11351136
body = bodyStream.stream
11361137
contentLength = bodyStream.length
1137-
} else if (util.isBlobLike(body) && request.contentType == null && body.type) {
1138-
headers.push('content-type', body.type)
1138+
} else if (util.isBlobLike(body) && request.contentType == null) {
1139+
const contentType = body.type
1140+
if (contentType) {
1141+
const contentTypeValue = `${contentType}`
1142+
if (!util.isValidHeaderValue(contentTypeValue)) {
1143+
util.errorRequest(client, request, new InvalidArgumentError('invalid content-type header'))
1144+
return false
1145+
}
1146+
headers.push('content-type', contentTypeValue)
1147+
}
11391148
}
11401149

11411150
if (body && typeof body.read === 'function') {

0 commit comments

Comments
 (0)