mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
formData: set default filename for Blob to <blob> (#5907)
This commit is contained in:
parent
3cbcdd4250
commit
c9bbb200d6
3 changed files with 30 additions and 3 deletions
|
@ -22,7 +22,7 @@ class FormDataBase {
|
|||
if (value instanceof domFile.DomFileImpl) {
|
||||
this[dataSymbol].push([name, value]);
|
||||
} else if (value instanceof blob.DenoBlob) {
|
||||
const dfile = new domFile.DomFileImpl([value], filename || name, {
|
||||
const dfile = new domFile.DomFileImpl([value], filename || "blob", {
|
||||
type: value.type,
|
||||
});
|
||||
this[dataSymbol].push([name, dfile]);
|
||||
|
@ -96,7 +96,7 @@ class FormDataBase {
|
|||
if (value instanceof domFile.DomFileImpl) {
|
||||
this[dataSymbol][i][1] = value;
|
||||
} else if (value instanceof blob.DenoBlob) {
|
||||
const dfile = new domFile.DomFileImpl([value], filename || name, {
|
||||
const dfile = new domFile.DomFileImpl([value], filename || "blob", {
|
||||
type: value.type,
|
||||
});
|
||||
this[dataSymbol][i][1] = dfile;
|
||||
|
@ -117,7 +117,7 @@ class FormDataBase {
|
|||
if (value instanceof domFile.DomFileImpl) {
|
||||
this[dataSymbol].push([name, value]);
|
||||
} else if (value instanceof blob.DenoBlob) {
|
||||
const dfile = new domFile.DomFileImpl([value], filename || name, {
|
||||
const dfile = new domFile.DomFileImpl([value], filename || "blob", {
|
||||
type: value.type,
|
||||
});
|
||||
this[dataSymbol].push([name, dfile]);
|
||||
|
|
|
@ -359,6 +359,24 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { net: true } },
|
||||
async function fetchInitFormDataBlobFilenameBody(): Promise<void> {
|
||||
const form = new FormData();
|
||||
form.append("field", "value");
|
||||
form.append("file", new Blob([new TextEncoder().encode("deno")]));
|
||||
const response = await fetch("http://localhost:4545/echo_server", {
|
||||
method: "POST",
|
||||
body: form,
|
||||
});
|
||||
const resultForm = await response.formData();
|
||||
assertEquals(form.get("field"), resultForm.get("field"));
|
||||
const file = resultForm.get("file");
|
||||
assert(file instanceof File);
|
||||
assertEquals(file.name, "blob");
|
||||
}
|
||||
);
|
||||
|
||||
unitTest({ perms: { net: true } }, async function fetchUserAgent(): Promise<
|
||||
void
|
||||
> {
|
||||
|
|
|
@ -99,6 +99,15 @@ unitTest(function formDataSetEmptyBlobSuccess(): void {
|
|||
*/
|
||||
});
|
||||
|
||||
unitTest(function formDataBlobFilename(): void {
|
||||
const formData = new FormData();
|
||||
const content = new TextEncoder().encode("deno");
|
||||
formData.set("a", new Blob([content]));
|
||||
const file = formData.get("a");
|
||||
assert(file instanceof File);
|
||||
assertEquals(file.name, "blob");
|
||||
});
|
||||
|
||||
unitTest(function formDataParamsForEachSuccess(): void {
|
||||
const init = [
|
||||
["a", "54"],
|
||||
|
|
Loading…
Reference in a new issue