diff options
author | zfx <502545703@qq.com> | 2020-05-20 02:22:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-19 14:22:26 -0400 |
commit | 7589d4d7c4a7c95298268eb8bea0e808feb0c6a9 (patch) | |
tree | 6a4439331da527163bd3fcd4f33e1e192f45b5e1 /std/textproto | |
parent | 9752b853ddac3ba41378d0ae8a8604a28e285ffb (diff) |
fix(multipart): fix error when parsing file name in utf8 format (#5428)
Diffstat (limited to 'std/textproto')
-rw-r--r-- | std/textproto/mod.ts | 8 |
1 files changed, 7 insertions, 1 deletions
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 |