-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforwarded.test.ts
95 lines (86 loc) · 1.86 KB
/
forwarded.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
95
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.
import { assertEquals } from "./deps_test.ts";
import { parse } from "./forwarded.ts";
Deno.test({
name: "parses the pairs as expected",
fn() {
assertEquals(parse("foo=a,foo=b;bar=c;baz=d;qux=e"), [{ foo: "a" }, {
foo: "b",
bar: "c",
baz: "d",
qux: "e",
}]);
},
});
Deno.test({
name: "handles double quotes and escaped characters",
fn() {
assertEquals(
parse([
'foo="bar"',
'foo="ba\\r"',
'foo=",;"',
'foo=""',
'foo=" "',
'foo="\t"',
'foo=" \t"',
'foo="\\""',
'foo="\\\\"',
'foo="\\\\\\a"',
'foo="¥"',
'foo="\\§"',
].join(",")),
[
{ foo: "bar" },
{ foo: "bar" },
{ foo: ",;" },
{ foo: "" },
{ foo: " " },
{ foo: "\t" },
{ foo: " \t" },
{ foo: '"' },
{ foo: "\\" },
{ foo: "\\a" },
{ foo: "¥" },
{ foo: "§" },
],
);
},
});
Deno.test({
name: "ignores the optional white spaces",
fn() {
assertEquals(parse('foo=a,foo=b, foo="c" ,foo=d , foo=e'), [
{ foo: "a" },
{ foo: "b" },
{ foo: "c" },
{ foo: "d" },
{ foo: "e" },
]);
assertEquals(parse('foo=a;bar=b; baz=c ;qux="d" ; norf=e'), [{
foo: "a",
bar: "b",
baz: "c",
qux: "d",
norf: "e",
}]);
},
});
Deno.test({
name: "ignores the case of parameter names",
fn() {
assertEquals(parse(`foo=a,Foo=""`), [{ foo: "a" }, { foo: "" }]);
},
});
Deno.test({
name: "does not allow empty parameters",
fn() {
assertEquals(parse("foo=bar,=baz"), undefined);
},
});
Deno.test({
name: "returns undefined if a parameter is not made of 1*tchar",
fn() {
assertEquals(parse("f@r=192.0.2.43"), undefined);
},
});