deno.land / std@0.173.0 / media_types / parse_media_type_test.ts

parse_media_type_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";import { parseMediaType } from "./mod.ts";
Deno.test({ name: "media_types - parseMediaType()", fn() { const nameFoo = { "name": "foo" }; const fixtures: [string, string, Record<string, string> | undefined][] = [ [`form-data; name="foo"`, "form-data", nameFoo], [` form-data ; name=foo`, "form-data", nameFoo], [`FORM-DATA;name="foo"`, "form-data", nameFoo], [` FORM-DATA ; name="foo"`, "form-data", nameFoo], [` FORM-DATA ; name="foo"`, "form-data", nameFoo], [`form-data; key=value; blah="value";name="foo" `, "form-data", { key: "value", blah: "value", name: "foo", }], [ `application/x-stuff; title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A`, "application/x-stuff", { title: "This is ***fun***", }, ], [ `message/external-body; access-type=URL; ` + `URL*0="ftp://";` + `URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"`, "message/external-body", { "access-type": "URL", url: "ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar", }, ], [ `application/x-stuff; ` + `title*0*=us-ascii'en'This%20is%20even%20more%20; ` + `title*1*=%2A%2A%2Afun%2A%2A%2A%20; ` + `title*2="isn't it!"`, `application/x-stuff`, { title: "This is even more ***fun*** isn't it!", }, ], [`attachment`, "attachment", undefined], [`ATTACHMENT`, "attachment", undefined], [`attachment; filename="foo.html"`, "attachment", { filename: "foo.html", }], [`attachment; filename="f\\oo.html"`, "attachment", { filename: "f\\oo.html", }], [`attachment; filename="Here's a semicolon;.html"`, "attachment", { filename: "Here's a semicolon;.html", }], [`attachment; filename="foo-%c3%a4-%e2%82%ac.html"`, "attachment", { filename: "foo-%c3%a4-%e2%82%ac.html", }], [ `attachment; filename*=''foo-%c3%a4-%e2%82%ac.html`, "attachment", undefined, ], [`attachment; filename*=UTF-8''foo-a%cc%88.html`, "attachment", { filename: "foo-ä.html", }], [`attachment; filename*0="foo."; filename*1="html"`, "attachment", { filename: "foo.html", }], [`form-data; firstname="Брэд"; lastname="Фицпатрик"`, "form-data", { firstname: "Брэд", lastname: "Фицпатрик", }], [ `form-data; name="file"; filename="C:\\dev\\go\\robots.txt"`, "form-data", { name: "file", filename: `C:\\dev\\go\\robots.txt` }, ], [ `form-data; name="file"; filename="C:\\新建文件夹\\中文第二次测试.mp4"`, "form-data", { name: "file", filename: `C:\\新建文件夹\\中文第二次测试.mp4` }, ], ];
for (const [fixture, mediaType, params] of fixtures) { assertEquals(parseMediaType(fixture), [mediaType, params]); } },});
std

Version Info

Tagged at
a year ago