fix(js): tolerate missing File constructor
Guard URL-encoded form serialization so constrained browser contexts without File still submit generated hemx forms instead of throwing before fetch. req: runtime/002
This commit is contained in:
@@ -153,7 +153,7 @@
|
|||||||
function urlEncoded(data) {
|
function urlEncoded(data) {
|
||||||
const encoded = new URLSearchParams();
|
const encoded = new URLSearchParams();
|
||||||
for (const [name, value] of data.entries()) {
|
for (const [name, value] of data.entries()) {
|
||||||
if (value instanceof File) continue;
|
if (typeof File !== "undefined" && value instanceof File) continue;
|
||||||
encoded.append(name, value);
|
encoded.append(name, value);
|
||||||
}
|
}
|
||||||
return encoded;
|
return encoded;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ fn runtime_preserves_multipart_file_upload_fallback_shape() {
|
|||||||
assert!(source.contains(
|
assert!(source.contains(
|
||||||
"multipart: form && String(form.enctype).toLowerCase() === \"multipart/form-data\""
|
"multipart: form && String(form.enctype).toLowerCase() === \"multipart/form-data\""
|
||||||
));
|
));
|
||||||
assert!(source.contains("if (value instanceof File) continue"));
|
assert!(source.contains("if (typeof File !== \"undefined\" && value instanceof File) continue"));
|
||||||
assert!(source.contains("return multipart ? data : urlEncoded(data)"));
|
assert!(source.contains("return multipart ? data : urlEncoded(data)"));
|
||||||
assert!(source.contains("if (body instanceof URLSearchParams) headers[\"Content-Type\"] = \"application/x-www-form-urlencoded;charset=UTF-8\""));
|
assert!(source.contains("if (body instanceof URLSearchParams) headers[\"Content-Type\"] = \"application/x-www-form-urlencoded;charset=UTF-8\""));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user