summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--std/mime/multipart.ts2
-rw-r--r--std/mime/multipart_test.ts4
-rw-r--r--std/mime/testdata/sample.txt30
-rw-r--r--std/textproto/mod.ts8
4 files changed, 31 insertions, 13 deletions
diff --git a/std/mime/multipart.ts b/std/mime/multipart.ts
index abe46f820..75d418c92 100644
--- a/std/mime/multipart.ts
+++ b/std/mime/multipart.ts
@@ -206,7 +206,7 @@ class PartReader implements Reader, Closer {
const cd = this.headers.get("content-disposition");
const params: { [key: string]: string } = {};
assert(cd != null, "content-disposition must be set");
- const comps = cd.split(";");
+ const comps = decodeURI(cd).split(";");
this.contentDisposition = comps[0];
comps
.slice(1)
diff --git a/std/mime/multipart_test.ts b/std/mime/multipart_test.ts
index e12a2f399..61afdba03 100644
--- a/std/mime/multipart_test.ts
+++ b/std/mime/multipart_test.ts
@@ -188,6 +188,10 @@ test({
const file = form.file("file");
assert(isFormFile(file));
assert(file.content !== void 0);
+ const file2 = form.file("file2");
+ assert(isFormFile(file2));
+ assert(file2.filename === "中文.json");
+ assert(file2.content !== void 0);
o.close();
},
});
diff --git a/std/mime/testdata/sample.txt b/std/mime/testdata/sample.txt
index 97e9bf553..8c7a1c204 100644
--- a/std/mime/testdata/sample.txt
+++ b/std/mime/testdata/sample.txt
@@ -12,16 +12,24 @@ bar
content-disposition: form-data; name="file"; filename="tsconfig.json"
content-type: application/octet-stream
-{
- "compilerOptions": {
- "target": "es2018",
- "baseUrl": ".",
- "paths": {
- "deno": ["./deno.d.ts"],
- "https://*": ["../../.deno/deps/https/*"],
- "http://*": ["../../.deno/deps/http/*"]
- }
- }
-}
+{
+ "compilerOptions": {
+ "target": "es2018",
+ "baseUrl": ".",
+ "paths": {
+ "deno": ["./deno.d.ts"],
+ "https://*": ["../../.deno/deps/https/*"],
+ "http://*": ["../../.deno/deps/http/*"]
+ }
+ }
+}
+
+----------------------------434049563556637648550474
+content-disposition: form-data; name="file2"; filename="中文.json"
+content-type: application/octet-stream
+
+{
+ "test": "filename"
+}
----------------------------434049563556637648550474--
diff --git a/std/textproto/mod.ts b/std/textproto/mod.ts
index 9b843e5b1..48bbed8bf 100644
--- a/std/textproto/mod.ts
+++ b/std/textproto/mod.ts
@@ -8,6 +8,9 @@ import { charCode } from "../io/util.ts";
import { concat } from "../bytes/mod.ts";
import { decode } from "../encoding/utf8.ts";
+// FROM https://github.com/denoland/deno/blob/b34628a26ab0187a827aa4ebe256e23178e25d39/cli/js/web/headers.ts#L9
+const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/g;
+
function str(buf: Uint8Array | null | undefined): string {
if (buf == null) {
return "";
@@ -102,7 +105,10 @@ export class TextProtoReader {
) {
i++;
}
- const value = str(kv.subarray(i));
+ const value = str(kv.subarray(i)).replace(
+ invalidHeaderCharRegex,
+ encodeURI
+ );
// In case of invalid header we swallow the error
// example: "Audio Mode" => invalid due to space in the key