From 7589d4d7c4a7c95298268eb8bea0e808feb0c6a9 Mon Sep 17 00:00:00 2001 From: zfx <502545703@qq.com> Date: Wed, 20 May 2020 02:22:26 +0800 Subject: fix(multipart): fix error when parsing file name in utf8 format (#5428) --- std/textproto/mod.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'std/textproto') 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 -- cgit v1.2.3