1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

formData: set default filename for Blob to <blob> (#5907)

This commit is contained in:
Marcos Casagrande 2020-05-28 15:02:00 +02:00 committed by GitHub
parent 3cbcdd4250
commit c9bbb200d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

View file

@ -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]);

View file

@ -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
> {

View file

@ -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"],