`Request/Response.formData()` throws ERR_ASSERTION on a multipart file part when `globalThis.File` is replaced
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #6212 của @xgauravyaduvanshii — đã đóng, không merge
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
Hướng nghiên cứu
Start with the bundled Undici multipart form data parser and the webidl.is.File brand check described in the issue. Reproduce with the dependency free plain.mjs example on Node v24 or v26, then compare with v22. Done means formData() returns the file part with content hello even after globalThis.File is replaced; an open linked pull request indicates work is already underway.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
v24.22.2 and v26.13.1. v22.23.3 is fine.
Platform
macOS (darwin arm64). Not platform-specific as far as I can tell.
Subsystem
fetch (bundled undici)
What steps will reproduce the bug?
plain.mjs, no dependencies:
const body =
"--b\r\n" +
'Content-Disposition: form-data; name="f"; filename="a.txt"\r\n' +
"Content-Type: text/plain\r\n\r\n" +
"hello\r\n" +
"--b--\r\n";
const parse = () =>
new Response(body, { headers: { "content-type": "multipart/form-data; boundary=b" } }).formData();
console.log((await parse()).get("f") instanceof File); // true
globalThis.File = class File extends Blob {
constructor(bits, name, opts) { super(bits, opts); this.name = name; }
};
await parse(); // v24/v26: AssertionError [ERR_ASSERTION]
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(typeof value === "string" && webidl.is.USVString(value) || webidl.is.File(value))
at multipartFormDataParser (node:internal/deps/undici/undici:...)
How often does it reproduce?
Always.
What is the expected behavior?
formData() returns a FormData whose "f" entry is a file with the content hello, as on v22. It shouldn't depend on what the global File binding currently points to.
What do you see instead?
multipartFormDataParser creates the part with new File(...), which looks up the global File at call time. It then checks the result with webidl.is.File, which is MakeTypeAssertion(File) taken from Node's own File when the module loads. Once the global is replaced, the object it just created fails the check.
Additional information
This is what happens under DOM test environments: vitest and jest with jsdom install the DOM's File on globalThis. Any Request.formData() on a multipart body with a file part then fails, which includes every MSW request handler that reads an upload.
The vitest + jsdom project below reproduces it in that setting (npm i && npx vitest run): it passes on v22.23.3 and fails on v24.22.2 and v26.13.1.
vitest + jsdom reproduction
package.json
{
"name": "undici-jsdom-formdata-repro",
"private": true,
"type": "module",
"scripts": { "test": "vitest run" },
"devDependencies": { "jsdom": "27.4.0", "vitest": "4.1.12" }
}
vitest.config.mjs
export default { test: { environment: "jsdom", execArgv: ["--no-experimental-webstorage"] } };
formdata.test.mjs
import { expect, test } from "vitest";
// Under jsdom, globalThis.File is jsdom's. Node's Request.formData() then fails on a file part.
test("Request.formData() parses a multipart file part under jsdom", async () => {
const body =
"--b\r\n" +
'Content-Disposition: form-data; name="f"; filename="a.txt"\r\n' +
"Content-Type: text/plain\r\n\r\n" +
"hello\r\n" +
"--b--\r\n";
const req = new Request("http://example.invalid/", {
method: "POST",
headers: { "content-type": "multipart/form-data; boundary=b" },
body,
});
const part = (await req.formData()).get("f");
expect(await part.text()).toBe("hello");
});
A possible fix: construct the part with the same internal File the brand check uses, instead of the global binding.
- Ngôn ngữ chính
- JavaScript
- Star
- 124k
- Fork
- 38k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 266
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nodejs/node
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
Maintainer thường phản hồi trong vòng 1 ngày
-
fs: document readStream.start and readStream.endCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởdoc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
nodejs/node#67848 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
doc: document the Buffer.prototype.*Slice() methodsCó thể đã có người làm @AyushCipher đã nhận hôm nay. Đang mởdoc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
nodejs/node#67847 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`styleText` fast path bypasses `options` and `options.validateStream` validationCó thể đã có người làm @GBra-4-669 đã nhận 8 ngày trước. Đang mởutil
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
riscv64
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nodejs/node#67655 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug triage needed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Resource]: PersephoneĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
hesreallyhim/awesome-claude-code#3773 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
tabatkins/railroad-diagrams#129 ·
-
web: api() turns a null or object-valued error body into a TypeError or "[object Object]" and loses the statusCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
OCM: shares using the `embedded` protocol are rejected with "Missing sharedSecret in protocol"Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày