Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/deps
diff options
context:
space:
mode:
authorNode.js GitHub Bot <github-bot@iojs.org>2022-08-10 01:55:40 +0300
committerRuy Adorno <ruyadorno@google.com>2022-08-23 02:37:21 +0300
commit818271c1c3b28464e10e8d87ddcb673b8bcb3e29 (patch)
treed9ff405691ddb8d6881af16a07626e3c81082156 /deps
parent340ca4d8feeb01149e3c83f7640e1476256bfc9f (diff)
deps: update undici to 5.8.2
PR-URL: https://github.com/nodejs/node/pull/44187 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'deps')
-rw-r--r--deps/undici/src/docs/api/MockAgent.md17
-rw-r--r--deps/undici/src/index.js7
-rw-r--r--deps/undici/src/lib/core/request.js3
-rw-r--r--deps/undici/src/lib/core/util.js17
-rw-r--r--deps/undici/src/lib/fetch/webidl.js15
-rw-r--r--deps/undici/src/package.json2
-rw-r--r--deps/undici/undici.js22
7 files changed, 64 insertions, 19 deletions
diff --git a/deps/undici/src/docs/api/MockAgent.md b/deps/undici/src/docs/api/MockAgent.md
index 5c8eda24937..85ae69046e7 100644
--- a/deps/undici/src/docs/api/MockAgent.md
+++ b/deps/undici/src/docs/api/MockAgent.md
@@ -177,6 +177,23 @@ for await (const data of result2.body) {
console.log('data', data.toString('utf8')) // data hello
}
```
+#### Example - Mock different requests within the same file
+```js
+const { MockAgent, setGlobalDispatcher } = require('undici');
+const agent = new MockAgent();
+agent.disableNetConnect();
+setGlobalDispatcher(agent);
+describe('Test', () => {
+ it('200', async () => {
+ const mockAgent = agent.get('http://test.com');
+ // your test
+ });
+ it('200', async () => {
+ const mockAgent = agent.get('http://testing.com');
+ // your test
+ });
+});
+```
#### Example - Mocked request with query body, headers and trailers
diff --git a/deps/undici/src/index.js b/deps/undici/src/index.js
index b2144c844ba..8099f5a692f 100644
--- a/deps/undici/src/index.js
+++ b/deps/undici/src/index.js
@@ -53,7 +53,12 @@ function makeDispatcher (fn) {
throw new InvalidArgumentError('invalid opts.path')
}
- url = new URL(opts.path, util.parseOrigin(url))
+ let path = opts.path
+ if (!opts.path.startsWith('/')) {
+ path = `/${path}`
+ }
+
+ url = new URL(util.parseOrigin(url).origin + path)
} else {
if (!opts) {
opts = typeof url === 'object' ? url : {}
diff --git a/deps/undici/src/lib/core/request.js b/deps/undici/src/lib/core/request.js
index 4dc2fcca0db..b05a16d7a01 100644
--- a/deps/undici/src/lib/core/request.js
+++ b/deps/undici/src/lib/core/request.js
@@ -297,7 +297,8 @@ function processHeader (request, key, val) {
} else if (
request.contentType === null &&
key.length === 12 &&
- key.toLowerCase() === 'content-type'
+ key.toLowerCase() === 'content-type' &&
+ headerCharRegex.exec(val) === null
) {
request.contentType = val
request.headers += `${key}: ${val}\r\n`
diff --git a/deps/undici/src/lib/core/util.js b/deps/undici/src/lib/core/util.js
index 635ef2e15f2..5b0c5d1ef39 100644
--- a/deps/undici/src/lib/core/util.js
+++ b/deps/undici/src/lib/core/util.js
@@ -108,14 +108,25 @@ function parseURL (url) {
const port = url.port != null
? url.port
: (url.protocol === 'https:' ? 443 : 80)
- const origin = url.origin != null
+ let origin = url.origin != null
? url.origin
: `${url.protocol}//${url.hostname}:${port}`
- const path = url.path != null
+ let path = url.path != null
? url.path
: `${url.pathname || ''}${url.search || ''}`
- url = new URL(path, origin)
+ if (origin.endsWith('/')) {
+ origin = origin.substring(0, origin.length - 1)
+ }
+
+ if (path && !path.startsWith('/')) {
+ path = `/${path}`
+ }
+ // new URL(path, origin) is unsafe when `path` contains an absolute URL
+ // From https://developer.mozilla.org/en-US/docs/Web/API/URL/URL:
+ // If first parameter is a relative URL, second param is required, and will be used as the base URL.
+ // If first parameter is an absolute URL, a given second param will be ignored.
+ url = new URL(origin + path)
}
return url
diff --git a/deps/undici/src/lib/fetch/webidl.js b/deps/undici/src/lib/fetch/webidl.js
index 293199e8f9b..430e657e275 100644
--- a/deps/undici/src/lib/fetch/webidl.js
+++ b/deps/undici/src/lib/fetch/webidl.js
@@ -388,10 +388,6 @@ webidl.converters.DOMString = function (V, opts = {}) {
return String(V)
}
-// Check for 0 or more characters outside of the latin1 range.
-// eslint-disable-next-line no-control-regex
-const isLatin1 = /^[\u0000-\u00ff]{0,}$/
-
// https://webidl.spec.whatwg.org/#es-ByteString
webidl.converters.ByteString = function (V) {
// 1. Let x be ? ToString(V).
@@ -400,8 +396,15 @@ webidl.converters.ByteString = function (V) {
// 2. If the value of any element of x is greater than
// 255, then throw a TypeError.
- if (!isLatin1.test(x)) {
- throw new TypeError('Argument is not a ByteString')
+ for (let index = 0; index < x.length; index++) {
+ const charCode = x.charCodeAt(index)
+
+ if (charCode > 255) {
+ throw new TypeError(
+ 'Cannot convert argument to a ByteString because the character at' +
+ `index ${index} has a value of ${charCode} which is greater than 255.`
+ )
+ }
}
// 3. Return an IDL ByteString value whose length is the
diff --git a/deps/undici/src/package.json b/deps/undici/src/package.json
index 4ac0eb8863d..0b9d4f713e4 100644
--- a/deps/undici/src/package.json
+++ b/deps/undici/src/package.json
@@ -1,6 +1,6 @@
{
"name": "undici",
- "version": "5.8.1",
+ "version": "5.8.2",
"description": "An HTTP/1.1 client, written from scratch for Node.js",
"homepage": "https://undici.nodejs.org",
"bugs": {
diff --git a/deps/undici/undici.js b/deps/undici/undici.js
index 123b51b4d30..a4536d4a530 100644
--- a/deps/undici/undici.js
+++ b/deps/undici/undici.js
@@ -737,9 +737,15 @@ var require_util = __commonJS({
}
if (!(url instanceof URL)) {
const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
- const origin = url.origin != null ? url.origin : `${url.protocol}//${url.hostname}:${port}`;
- const path = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
- url = new URL(path, origin);
+ let origin = url.origin != null ? url.origin : `${url.protocol}//${url.hostname}:${port}`;
+ let path = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
+ if (origin.endsWith("/")) {
+ origin = origin.substring(0, origin.length - 1);
+ }
+ if (path && !path.startsWith("/")) {
+ path = `/${path}`;
+ }
+ url = new URL(origin + path);
}
return url;
}
@@ -1281,11 +1287,13 @@ var require_webidl = __commonJS({
}
return String(V);
};
- var isLatin1 = /^[\u0000-\u00ff]{0,}$/;
webidl.converters.ByteString = function(V) {
const x = webidl.converters.DOMString(V);
- if (!isLatin1.test(x)) {
- throw new TypeError("Argument is not a ByteString");
+ for (let index = 0; index < x.length; index++) {
+ const charCode = x.charCodeAt(index);
+ if (charCode > 255) {
+ throw new TypeError(`Cannot convert argument to a ByteString because the character atindex ${index} has a value of ${charCode} which is greater than 255.`);
+ }
}
return x;
};
@@ -2580,7 +2588,7 @@ var require_request = __commonJS({
if (!Number.isFinite(request.contentLength)) {
throw new InvalidArgumentError("invalid content-length header");
}
- } else if (request.contentType === null && key.length === 12 && key.toLowerCase() === "content-type") {
+ } else if (request.contentType === null && key.length === 12 && key.toLowerCase() === "content-type" && headerCharRegex.exec(val) === null) {
request.contentType = val;
request.headers += `${key}: ${val}\r
`;