@kavach/cookie 1.0.0-next.3 → 1.0.0-next.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -61
- package/dist/index.d.ts +0 -6
- package/package.json +14 -31
- package/src/index.js +45 -51
- package/.turbo/turbo-coverage.log +0 -23
- package/.turbo/turbo-format.log +0 -16
- package/.turbo/turbo-lint.log +0 -6
- package/.turbo/turbo-prepublishOnly.log +0 -4
- package/.turbo/turbo-test:ci.log +0 -15
- package/.turbo/turbo-upgrade.log +0 -23
- package/LICENSE +0 -21
- package/benchmark/index.js +0 -9
- package/benchmark/parse-top.js +0 -37
- package/benchmark/parse.js +0 -79
- package/benchmark/top-sites.js +0 -31
- package/dist/index.d.ts.map +0 -1
- package/spec/parse.spec.js +0 -91
- package/spec/serialize.spec.js +0 -169
- package/tsconfig.json +0 -8
- package/vitest.config.js +0 -13
package/README.md
CHANGED
|
@@ -202,71 +202,12 @@ http.createServer(onRequest).listen(3000)
|
|
|
202
202
|
## Testing
|
|
203
203
|
|
|
204
204
|
```sh
|
|
205
|
-
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Benchmark
|
|
209
|
-
|
|
210
|
-
```text
|
|
211
|
-
$ pnpm bench
|
|
212
|
-
|
|
213
|
-
> @kavach/cookie@1.0.0-next.0 bench cookie
|
|
214
|
-
> node benchmark/index.js
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
node@16.15.0
|
|
218
|
-
v8@9.4.146.24-node.20
|
|
219
|
-
uv@1.43.0
|
|
220
|
-
zlib@1.2.11
|
|
221
|
-
brotli@1.0.9
|
|
222
|
-
ares@1.18.1
|
|
223
|
-
modules@93
|
|
224
|
-
nghttp2@1.47.0
|
|
225
|
-
napi@8
|
|
226
|
-
llhttp@6.0.4
|
|
227
|
-
openssl@1.1.1n+quic
|
|
228
|
-
cldr@40.0
|
|
229
|
-
icu@70.1
|
|
230
|
-
tz@2021a3
|
|
231
|
-
unicode@14.0
|
|
232
|
-
ngtcp2@0.1.0-DEV
|
|
233
|
-
nghttp3@0.1.0-DEV
|
|
234
|
-
cookie.parse - generic
|
|
235
|
-
|
|
236
|
-
6 tests completed.
|
|
237
|
-
|
|
238
|
-
simple x 2,285,991 ops/sec ±1.46% (191 runs sampled)
|
|
239
|
-
decode x 1,720,499 ops/sec ±1.25% (189 runs sampled)
|
|
240
|
-
unquote x 1,883,221 ops/sec ±1.30% (186 runs sampled)
|
|
241
|
-
duplicates x 765,346 ops/sec ±1.46% (185 runs sampled)
|
|
242
|
-
10 cookies x 225,063 ops/sec ±1.04% (185 runs sampled)
|
|
243
|
-
100 cookies x 20,354 ops/sec ±1.17% (185 runs sampled)
|
|
244
|
-
|
|
245
|
-
cookie.parse - top sites
|
|
246
|
-
|
|
247
|
-
16 tests completed.
|
|
248
|
-
|
|
249
|
-
parse accounts.google.com x 1,096,402 ops/sec ±0.76% (193 runs sampled)
|
|
250
|
-
parse apple.com x 2,229,368 ops/sec ±1.14% (184 runs sampled)
|
|
251
|
-
parse cloudflare.com x 665,688 ops/sec ±0.91% (183 runs sampled)
|
|
252
|
-
parse docs.google.com x 974,477 ops/sec ±1.07% (181 runs sampled)
|
|
253
|
-
parse drive.google.com x 1,044,377 ops/sec ±0.95% (188 runs sampled)
|
|
254
|
-
parse en.wikipedia.org x 444,311 ops/sec ±1.14% (184 runs sampled)
|
|
255
|
-
parse linkedin.com x 287,581 ops/sec ±0.84% (186 runs sampled)
|
|
256
|
-
parse maps.google.com x 481,702 ops/sec ±0.88% (185 runs sampled)
|
|
257
|
-
parse microsoft.com x 249,242 ops/sec ±0.92% (183 runs sampled)
|
|
258
|
-
parse play.google.com x 686,403 ops/sec ±0.92% (187 runs sampled)
|
|
259
|
-
parse plus.google.com x 989,099 ops/sec ±0.86% (184 runs sampled)
|
|
260
|
-
parse sites.google.com x 975,948 ops/sec ±1.71% (182 runs sampled)
|
|
261
|
-
parse support.google.com x 552,380 ops/sec ±1.03% (189 runs sampled)
|
|
262
|
-
parse www.google.com x 507,071 ops/sec ±0.96% (181 runs sampled)
|
|
263
|
-
parse youtu.be x 941,225 ops/sec ±0.97% (194 runs sampled)
|
|
264
|
-
parse youtube.com x 976,920 ops/sec ±0.61% (192 runs sampled)
|
|
205
|
+
bun test
|
|
265
206
|
```
|
|
266
207
|
|
|
267
208
|
## References
|
|
268
209
|
|
|
269
|
-
This library is an ES module version of [jshttp/cookie](https://github.com/jshttp/cookie), for working with cookies
|
|
210
|
+
This library is an ES module version of [jshttp/cookie](https://github.com/jshttp/cookie), for working with cookies.
|
|
270
211
|
|
|
271
212
|
- [RFC 6265: HTTP State Management Mechanism][rfc-6265]
|
|
272
213
|
- [Same-site Cookies][rfc-6265bis-09-5.4.7]
|
package/dist/index.d.ts
CHANGED
|
@@ -26,9 +26,3 @@ export function parse(str: string, options?: object): object;
|
|
|
26
26
|
* @public
|
|
27
27
|
*/
|
|
28
28
|
export function serialize(name: string, val: string, options?: object): string;
|
|
29
|
-
declare namespace _default {
|
|
30
|
-
export { parse };
|
|
31
|
-
export { serialize };
|
|
32
|
-
}
|
|
33
|
-
export default _default;
|
|
34
|
-
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kavach/cookie",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.31",
|
|
4
4
|
"description": "Cookie serialize/deserialize forked from jshttp/cookie",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"cookie",
|
|
9
9
|
"cookies"
|
|
10
10
|
],
|
|
11
|
-
"main": "index.js",
|
|
12
11
|
"module": "src/index.js",
|
|
13
12
|
"types": "dist/index.d.ts",
|
|
14
13
|
"type": "module",
|
|
@@ -21,39 +20,23 @@
|
|
|
21
20
|
"publishConfig": {
|
|
22
21
|
"access": "public"
|
|
23
22
|
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"@vitest/coverage-c8": "^0.24.5",
|
|
29
|
-
"@vitest/ui": "~0.12.10",
|
|
30
|
-
"beautify-benchmark": "0.2.4",
|
|
31
|
-
"benchmark": "2.1.4",
|
|
32
|
-
"c8": "^7.12.0",
|
|
33
|
-
"safe-buffer": "5.2.1",
|
|
34
|
-
"top-sites": "1.1.97",
|
|
35
|
-
"typescript": "^4.9.4",
|
|
36
|
-
"vite": "^4.0.3",
|
|
37
|
-
"vitest": "0.24.5",
|
|
38
|
-
"eslint-config-library": "1.0.0",
|
|
39
|
-
"shared-config": "1.0.0"
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prepublishOnly": "bun clean && bun tsc --project tsconfig.build.json",
|
|
25
|
+
"clean": "rm -rf dist",
|
|
26
|
+
"build": "bun prepublishOnly"
|
|
40
27
|
},
|
|
28
|
+
"files": [
|
|
29
|
+
"src/**/*.js",
|
|
30
|
+
"dist/**/*.d.ts",
|
|
31
|
+
"README.md",
|
|
32
|
+
"package.json"
|
|
33
|
+
],
|
|
41
34
|
"exports": {
|
|
42
35
|
"./package.json": "./package.json",
|
|
43
|
-
"./provider.css": "./src/provider.css",
|
|
44
36
|
".": {
|
|
45
37
|
"types": "./dist/index.d.ts",
|
|
46
|
-
"import": "./src/index.js"
|
|
38
|
+
"import": "./src/index.js",
|
|
39
|
+
"svelte": "./src/index.js"
|
|
47
40
|
}
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"bench": "node benchmark/index.js",
|
|
51
|
-
"lint": "prettier --check --plugin-search-dir=. . && eslint .",
|
|
52
|
-
"format": "prettier --write --plugin-search-dir=. .",
|
|
53
|
-
"test:ci": "vitest run",
|
|
54
|
-
"test:ui": "vitest --ui",
|
|
55
|
-
"test": "vitest",
|
|
56
|
-
"coverage": "vitest run --coverage",
|
|
57
|
-
"upgrade": "pnpm upgrade"
|
|
58
41
|
}
|
|
59
|
-
}
|
|
42
|
+
}
|
package/src/index.js
CHANGED
|
@@ -14,9 +14,25 @@
|
|
|
14
14
|
* @private
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const decode = decodeURIComponent
|
|
18
|
+
const encode = encodeURIComponent
|
|
19
|
+
const pairSplitRegExp = /; */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Try decoding a string using a decoding function.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} str
|
|
25
|
+
* @param {function} decodeFn
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
function tryDecode(str, decodeFn) {
|
|
29
|
+
try {
|
|
30
|
+
return decodeFn(str)
|
|
31
|
+
// eslint-disable-next-line no-unused-vars
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return str
|
|
34
|
+
}
|
|
35
|
+
}
|
|
20
36
|
|
|
21
37
|
/**
|
|
22
38
|
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
@@ -26,8 +42,7 @@ var pairSplitRegExp = /; */
|
|
|
26
42
|
* obs-text = %x80-FF
|
|
27
43
|
*/
|
|
28
44
|
|
|
29
|
-
|
|
30
|
-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/
|
|
45
|
+
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/u
|
|
31
46
|
|
|
32
47
|
/**
|
|
33
48
|
* Parse a cookie header.
|
|
@@ -40,36 +55,36 @@ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/
|
|
|
40
55
|
* @return {object}
|
|
41
56
|
* @public
|
|
42
57
|
*/
|
|
43
|
-
|
|
58
|
+
// eslint-disable-next-line
|
|
44
59
|
export function parse(str, options) {
|
|
45
60
|
if (typeof str !== 'string') {
|
|
46
61
|
throw new TypeError('argument str must be a string')
|
|
47
62
|
}
|
|
48
63
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
const obj = {}
|
|
65
|
+
const opt = options || {}
|
|
66
|
+
const pairs = str.split(pairSplitRegExp)
|
|
67
|
+
const dec = opt.decode || decode
|
|
53
68
|
|
|
54
|
-
for (
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
70
|
+
const pair = pairs[i]
|
|
71
|
+
let eq_idx = pair.indexOf('=')
|
|
57
72
|
|
|
58
73
|
// skip things that don't look like key=value
|
|
59
74
|
if (eq_idx < 0) {
|
|
60
75
|
continue
|
|
61
76
|
}
|
|
62
77
|
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
const key = pair.slice(0, eq_idx).trim()
|
|
79
|
+
let val = pair.slice(++eq_idx, pair.length).trim()
|
|
65
80
|
|
|
66
81
|
// quoted values
|
|
67
|
-
if (
|
|
82
|
+
if (val[0] === '"') {
|
|
68
83
|
val = val.slice(1, -1)
|
|
69
84
|
}
|
|
70
85
|
|
|
71
86
|
// only assign once
|
|
72
|
-
if (
|
|
87
|
+
if (obj[key] === undefined) {
|
|
73
88
|
obj[key] = tryDecode(val, dec)
|
|
74
89
|
}
|
|
75
90
|
}
|
|
@@ -92,10 +107,10 @@ export function parse(str, options) {
|
|
|
92
107
|
* @return {string}
|
|
93
108
|
* @public
|
|
94
109
|
*/
|
|
95
|
-
|
|
110
|
+
// eslint-disable-next-line
|
|
96
111
|
export function serialize(name, val, options) {
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
const opt = { maxAge: null, ...(options || {}) }
|
|
113
|
+
const enc = opt.encode || encode
|
|
99
114
|
|
|
100
115
|
if (typeof enc !== 'function') {
|
|
101
116
|
throw new TypeError('option encode is invalid')
|
|
@@ -105,22 +120,22 @@ export function serialize(name, val, options) {
|
|
|
105
120
|
throw new TypeError('argument name is invalid')
|
|
106
121
|
}
|
|
107
122
|
|
|
108
|
-
|
|
123
|
+
const value = enc(val)
|
|
109
124
|
|
|
110
125
|
if (value && !fieldContentRegExp.test(value)) {
|
|
111
126
|
throw new TypeError('argument val is invalid')
|
|
112
127
|
}
|
|
113
128
|
|
|
114
|
-
|
|
129
|
+
let str = `${name}=${value}`
|
|
115
130
|
|
|
116
|
-
if (
|
|
117
|
-
|
|
131
|
+
if (opt.maxAge !== null) {
|
|
132
|
+
// const maxAge = Number(opt.maxAge) - 0
|
|
118
133
|
|
|
119
|
-
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
134
|
+
if (isNaN(opt.maxAge) || !isFinite(opt.maxAge)) {
|
|
120
135
|
throw new TypeError('option maxAge is invalid')
|
|
121
136
|
}
|
|
122
137
|
|
|
123
|
-
str +=
|
|
138
|
+
str += `; Max-Age=${Math.floor(Number(opt.maxAge))}`
|
|
124
139
|
}
|
|
125
140
|
|
|
126
141
|
if (opt.domain) {
|
|
@@ -128,7 +143,7 @@ export function serialize(name, val, options) {
|
|
|
128
143
|
throw new TypeError('option domain is invalid')
|
|
129
144
|
}
|
|
130
145
|
|
|
131
|
-
str +=
|
|
146
|
+
str += `; Domain=${opt.domain}`
|
|
132
147
|
}
|
|
133
148
|
|
|
134
149
|
if (opt.path) {
|
|
@@ -136,7 +151,7 @@ export function serialize(name, val, options) {
|
|
|
136
151
|
throw new TypeError('option path is invalid')
|
|
137
152
|
}
|
|
138
153
|
|
|
139
|
-
str +=
|
|
154
|
+
str += `; Path=${opt.path}`
|
|
140
155
|
}
|
|
141
156
|
|
|
142
157
|
if (opt.expires) {
|
|
@@ -144,7 +159,7 @@ export function serialize(name, val, options) {
|
|
|
144
159
|
throw new TypeError('option expires is invalid')
|
|
145
160
|
}
|
|
146
161
|
|
|
147
|
-
str +=
|
|
162
|
+
str += `; Expires=${opt.expires.toUTCString()}`
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
if (opt.httpOnly) {
|
|
@@ -156,7 +171,7 @@ export function serialize(name, val, options) {
|
|
|
156
171
|
}
|
|
157
172
|
|
|
158
173
|
if (opt.sameSite) {
|
|
159
|
-
|
|
174
|
+
const sameSite =
|
|
160
175
|
typeof opt.sameSite === 'string'
|
|
161
176
|
? opt.sameSite.toLowerCase()
|
|
162
177
|
: opt.sameSite
|
|
@@ -181,24 +196,3 @@ export function serialize(name, val, options) {
|
|
|
181
196
|
|
|
182
197
|
return str
|
|
183
198
|
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Try decoding a string using a decoding function.
|
|
187
|
-
*
|
|
188
|
-
* @param {string} str
|
|
189
|
-
* @param {function} decode
|
|
190
|
-
* @private
|
|
191
|
-
*/
|
|
192
|
-
|
|
193
|
-
function tryDecode(str, decode) {
|
|
194
|
-
try {
|
|
195
|
-
return decode(str)
|
|
196
|
-
} catch (e) {
|
|
197
|
-
return str
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export default {
|
|
202
|
-
parse,
|
|
203
|
-
serialize
|
|
204
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @kavach/cookie@1.0.0-next.2 coverage /Users/Jerry/Code/Vikalp/kavach/packages/cookie
|
|
3
|
-
> vitest run --coverage
|
|
4
|
-
|
|
5
|
-
c
|
|
6
|
-
RUN v0.24.5 /Users/Jerry/Code/Vikalp/kavach/packages/cookie
|
|
7
|
-
Coverage enabled with c8
|
|
8
|
-
|
|
9
|
-
✓ spec/serialize.spec.js (11 tests) 16ms
|
|
10
|
-
✓ spec/parse.spec.js (10 tests) 16ms
|
|
11
|
-
|
|
12
|
-
Test Files 2 passed (2)
|
|
13
|
-
Tests 21 passed (21)
|
|
14
|
-
Start at 11:09:04
|
|
15
|
-
Duration 4.35s (transform 784ms, setup 0ms, collect 242ms, tests 32ms)
|
|
16
|
-
|
|
17
|
-
% Coverage report from c8
|
|
18
|
-
----------|---------|----------|---------|---------|-------------------
|
|
19
|
-
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
20
|
-
----------|---------|----------|---------|---------|-------------------
|
|
21
|
-
All files | 100 | 100 | 100 | 100 |
|
|
22
|
-
index.js | 100 | 100 | 100 | 100 |
|
|
23
|
-
----------|---------|----------|---------|---------|-------------------
|
package/.turbo/turbo-format.log
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @kavach/cookie@1.0.0-next.2 format /Users/Jerry/Code/Vikalp/kavach/packages/cookie
|
|
3
|
-
> prettier --write --plugin-search-dir=. .
|
|
4
|
-
|
|
5
|
-
.eslintrc 33ms
|
|
6
|
-
benchmark/index.js 21ms
|
|
7
|
-
benchmark/parse-top.js 19ms
|
|
8
|
-
benchmark/parse.js 23ms
|
|
9
|
-
benchmark/top-sites.js 12ms
|
|
10
|
-
package.json 4ms
|
|
11
|
-
README.md 132ms
|
|
12
|
-
spec/parse.spec.js 26ms
|
|
13
|
-
spec/serialize.spec.js 51ms
|
|
14
|
-
src/index.js 32ms
|
|
15
|
-
tsconfig.json 3ms
|
|
16
|
-
vitest.config.js 5ms
|
package/.turbo/turbo-lint.log
DELETED
package/.turbo/turbo-test:ci.log
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @kavach/cookie@1.0.0-next.3 test:ci /Users/Jerry/Code/Vikalp/kavach/packages/cookie
|
|
3
|
-
> vitest run
|
|
4
|
-
|
|
5
|
-
c
|
|
6
|
-
RUN v0.24.5 /Users/Jerry/Code/Vikalp/kavach/packages/cookie
|
|
7
|
-
|
|
8
|
-
✓ spec/serialize.spec.js (11 tests) 13ms
|
|
9
|
-
✓ spec/parse.spec.js (10 tests) 81ms
|
|
10
|
-
|
|
11
|
-
Test Files 2 passed (2)
|
|
12
|
-
Tests 21 passed (21)
|
|
13
|
-
Start at 11:57:43
|
|
14
|
-
Duration 3.68s (transform 1.91s, setup 1ms, collect 340ms, tests 94ms)
|
|
15
|
-
|
package/.turbo/turbo-upgrade.log
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @kavach/cookie@1.0.0-next.3 upgrade /Users/Jerry/Code/Vikalp/kavach/packages/cookie
|
|
3
|
-
> pnpm upgrade
|
|
4
|
-
|
|
5
|
-
../.. | Progress: resolved 1, reused 0, downloaded 0, added 0
|
|
6
|
-
../.. | Progress: resolved 5, reused 5, downloaded 0, added 0
|
|
7
|
-
../.. | Progress: resolved 6, reused 6, downloaded 0, added 0
|
|
8
|
-
../.. | Progress: resolved 10, reused 10, downloaded 0, added 0
|
|
9
|
-
../.. | Progress: resolved 11, reused 10, downloaded 0, added 0
|
|
10
|
-
../.. | Progress: resolved 12, reused 12, downloaded 0, added 0
|
|
11
|
-
../.. | Progress: resolved 13, reused 12, downloaded 0, added 0
|
|
12
|
-
../.. | Progress: resolved 63, reused 63, downloaded 0, added 0
|
|
13
|
-
../.. | Progress: resolved 212, reused 170, downloaded 0, added 0
|
|
14
|
-
../.. | +5 +
|
|
15
|
-
../.. | Progress: resolved 213, reused 171, downloaded 0, added 0, done
|
|
16
|
-
|
|
17
|
-
devDependencies:
|
|
18
|
-
- @types/node
|
|
19
|
-
+ @types/node 18.11.18
|
|
20
|
-
- vite
|
|
21
|
-
+ vite 4.0.3
|
|
22
|
-
|
|
23
|
-
Done in 15.7s
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Jerry Thomas
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/benchmark/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { suite as parseSuite } from './parse.js'
|
|
2
|
-
import { suite as parseTopSuite } from './parse-top.js'
|
|
3
|
-
|
|
4
|
-
for (let dep in process.versions) {
|
|
5
|
-
console.log(' %s@%s', dep, process.versions[dep])
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
parseSuite.run({ async: false })
|
|
9
|
-
parseTopSuite.run({ async: false })
|
package/benchmark/parse-top.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import pkg from 'benchmark'
|
|
6
|
-
import { add, log } from 'beautify-benchmark'
|
|
7
|
-
import { topSites } from './top-sites.js'
|
|
8
|
-
import * as cookie from '../src/index.js'
|
|
9
|
-
|
|
10
|
-
const { Suite } = pkg
|
|
11
|
-
/**
|
|
12
|
-
* Globals for benchmark.js
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
global.cookie = cookie
|
|
16
|
-
|
|
17
|
-
export const suite = new Suite()
|
|
18
|
-
|
|
19
|
-
Object.keys(topSites).forEach(function (domain) {
|
|
20
|
-
suite.add({
|
|
21
|
-
name: 'parse ' + domain,
|
|
22
|
-
minSamples: 100,
|
|
23
|
-
fn: 'let val = cookie.parse(' + JSON.stringify(topSites[domain]) + ')'
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
suite.on('start', function onCycle() {
|
|
28
|
-
process.stdout.write(' cookie.parse - top sites\n\n')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
suite.on('cycle', function onCycle(event) {
|
|
32
|
-
add(event.target)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
suite.on('complete', function onComplete() {
|
|
36
|
-
log()
|
|
37
|
-
})
|
package/benchmark/parse.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import pkg from 'benchmark'
|
|
6
|
-
import { add, log } from 'beautify-benchmark'
|
|
7
|
-
import * as cookie from '../src/index.js'
|
|
8
|
-
|
|
9
|
-
const { Suite } = pkg
|
|
10
|
-
/**
|
|
11
|
-
* Globals for benchmark.js
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
global.cookie = cookie
|
|
15
|
-
|
|
16
|
-
export const suite = new Suite()
|
|
17
|
-
|
|
18
|
-
suite.add({
|
|
19
|
-
name: 'simple',
|
|
20
|
-
minSamples: 100,
|
|
21
|
-
fn: 'let val = cookie.parse("foo=bar")'
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
suite.add({
|
|
25
|
-
name: 'decode',
|
|
26
|
-
minSamples: 100,
|
|
27
|
-
fn: 'let val = cookie.parse("foo=hello%20there!")'
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
suite.add({
|
|
31
|
-
name: 'unquote',
|
|
32
|
-
minSamples: 100,
|
|
33
|
-
fn: 'let val = cookie.parse("foo=\\"foo bar\\"")'
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
suite.add({
|
|
37
|
-
name: 'duplicates',
|
|
38
|
-
minSamples: 100,
|
|
39
|
-
fn:
|
|
40
|
-
'let val = cookie.parse(' +
|
|
41
|
-
JSON.stringify(gencookies(2) + '; ' + gencookies(2)) +
|
|
42
|
-
')'
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
suite.add({
|
|
46
|
-
name: '10 cookies',
|
|
47
|
-
minSamples: 100,
|
|
48
|
-
fn: 'let val = cookie.parse(' + JSON.stringify(gencookies(10)) + ')'
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
suite.add({
|
|
52
|
-
name: '100 cookies',
|
|
53
|
-
minSamples: 100,
|
|
54
|
-
fn: 'let val = cookie.parse(' + JSON.stringify(gencookies(100)) + ')'
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
suite.on('start', function onCycle() {
|
|
58
|
-
process.stdout.write(' cookie.parse - generic\n\n')
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
suite.on('cycle', function onCycle(event) {
|
|
62
|
-
add(event.target)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
suite.on('complete', function onComplete() {
|
|
66
|
-
log()
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
// suite.run({ async: false })
|
|
70
|
-
|
|
71
|
-
function gencookies(num) {
|
|
72
|
-
let str = ''
|
|
73
|
-
|
|
74
|
-
for (let i = 0; i < num; i++) {
|
|
75
|
-
str += '; foo' + i + '=bar'
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return str.slice(2)
|
|
79
|
-
}
|
package/benchmark/top-sites.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export const topSites = {
|
|
2
|
-
'accounts.google.com':
|
|
3
|
-
'__Ulll-UUUU=0:0U0lUlllUUUl0lUl00UUUUUU0lUlll:l0ll0UlUU0l0lUUU',
|
|
4
|
-
'apple.com': 'lll=UU',
|
|
5
|
-
'cloudflare.com':
|
|
6
|
-
'__ll_ll=lUllUll.0Ul0Ull0UUUU.ll_U0lllUU0UlUll0lUllU-0000000000-0-UUUl+0Ulll0UUUU0U0Ullll0UUUUUlllU0UUUUlUUUlUUUUUUUlUlUUll0l0UlUlUl0Ul000UUlUU0/0l0l0UU0UllUU0U0lU/lllU0lUllU',
|
|
7
|
-
'docs.google.com':
|
|
8
|
-
'__Ulll-UUUU=0:Ulll0UlUUllUlUl0UUlUUlUU0UUUUU:U0U0U0llUU0-0Ul0',
|
|
9
|
-
'drive.google.com':
|
|
10
|
-
'__Ulll-UUUU=0:UUll0UllUUll0lUU0llUUllUllUlll:U0UllUlll-lU0lll',
|
|
11
|
-
'en.wikipedia.org':
|
|
12
|
-
'UUU-Ulll-Ulllll=00-Ull-0000; UUU-Ulll-Ulllll-Ulllll=00-Ull-0000; UllUU=UU:UU:Ulllllllllll:00.00:-00.00:l0',
|
|
13
|
-
'linkedin.com':
|
|
14
|
-
'UUUUUUUUUU=llll:0000000000000000000; llll=l=0&llll=ll-ll; lllllll="l=0&ll000l0l-0lll-00l0-0000-0lll0ll0ll00"; llllllll="l=0&0000000000000000l0l000-0l0l-0000-0000-0l0l00l0000lUUUUUl_llU0UlUllUUlU0lUlUl00llUl"; llll="l=UUUU00:l=U:l=U:l=U:l=U:l=0000:l=0:l=0:l=0000000000:l=0000000000:l=0:lll=UUUUUlUlUUUUUUllllllU0UUlUlU0lll"',
|
|
15
|
-
'maps.google.com':
|
|
16
|
-
'0U_UUU=0000-00-00-00; UUU=000=UllUl00U-UU0llllUU0lUUlUl0llUl0U0lllUlUUU0l00UUUllllUlU0l0UllUUlUlU0UllUllU0UUlU00llUUUllUUlUl00lUlUUUlUUU0Ul00lllUUUUllUUl0UUlU0UllUlUUllllUllUllUll0llllllllll0lUUUlU0Ull',
|
|
17
|
-
'microsoft.com':
|
|
18
|
-
'llUllllUllllll=0; UUUU=0UUU00U0000000U0000U000000UU00UU; U-UU-UUUUUUUU=lll=00000l0%2200000l%22llllll000l0%22llllllllllll000%22lllllllllll%22llllllllllllllll%22llllllllllllllll%22llllllllllllllllllllll%22llllllllllllllllll%22lll-lll-lllll0l0ll%22llllllllllll%22lllllllllllllllll%2200000l0ll&lll=0ll00ll0-000l-000l-l000-l00ll0l0l00l; U-UU-Ulll=0; lllll_UllUU=0000000000~ll=00~ll=0lll000ll0l0000lll000lll0ll0000l; lllll_UllUU=0000000000~ll=00~ll=0lll000ll0l0000lll000lll0ll0000l',
|
|
19
|
-
'play.google.com':
|
|
20
|
-
'UUU=000=Ull0l00UlllUUUlU0UllUl0llU0l-lllUllUl0lllUU0UUU0lUlU-UUll000lUl00U0Ul_UlUU0l0lUUUUlUUl0UlUl0lU0-lll0l0l0UlUllllU0U0UU0U00UllU0l0lU0lll_0lUUU0UllUUUUll0UlUl0l0UUUUU00UUllll',
|
|
21
|
-
'plus.google.com':
|
|
22
|
-
'__Ulll-UUUU=0:0Ull0lUU0UUUlll0U-UllUUllllUlU:lll00_lllUUUUUUU',
|
|
23
|
-
'sites.google.com':
|
|
24
|
-
'__Ulll-UUUU=0:_UU0lll0UUUUlUU0lUll0UUlllllUl:UUll0lllU0UUlll0',
|
|
25
|
-
'support.google.com':
|
|
26
|
-
'UUU=000=llU0lUlllUUlllUUll0U0UUll0UUlUUlU-lUUllU0UllUlUUlUlU0UlUUU_U-UlUU0lUUlUllUlUlUUl00llllUl0lUUUU00Ul0UUlUll0UUUU_UUlUlllUllllU0U0lllllUlU000UllUl--UUU_ll_lllU0UllUUlllU00UlU; UUU=000=llU0lUlllUUlllUUll0U0UUll0UUlUUlU-lUUllU0UllUlUUlUlU0UlUUU_U-UlUU0lUUlUllUlUlUUl00llllUl0lUUUU00Ul0UUlUll0UUUU_UUlUlllUllllU0U0lllllUlU000UllUl--UUU_ll_lllU0UllUUlllU00UlU',
|
|
27
|
-
'www.google.com':
|
|
28
|
-
'0U_UUU=0000-00-00-00; UUU=UUUU_UUUlUUUUlUll_lllll0U00UUl0lllUUUUlUU_0_llUl0l0UUlU0_lU; UUU=000=lll0lUlUlllUll00U_lUlUUUUlll0lUlUU0lllUlllUllUUUll0U_U0llUU0UlU0Ull0U_l-_UUl00lUllUl0UUllUlUll0UUllUUUlU0UUlUllUlUUUlUllU-lUUlll0UlU0lUllUUUUlUUUlUlUU0llll_lU0lUlllll_UlUl',
|
|
29
|
-
'youtu.be': 'UUU=0; UUU=UUUUUUUllUU; UUUUUUU_UUUU0_UUUU=00UlUU-UUU0',
|
|
30
|
-
'youtube.com': 'UUU=0; UUU=lU0lUUUlUll; UUUUUUU_UUUU0_UUUU=0UUUlUllU0l'
|
|
31
|
-
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA+BA;;;;;;;;;;GAUG;AAEH,2BANW,MAAM,YACN,MAAM,GACL,MAAM,CAsCjB;AAED;;;;;;;;;;;;;;GAcG;AAEH,gCAPW,MAAM,OACN,MAAM,YACN,MAAM,GACL,MAAM,CA2FjB"}
|
package/spec/parse.spec.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { parse } from '../src/index.js'
|
|
3
|
-
|
|
4
|
-
describe('Cookie Parser', () => {
|
|
5
|
-
it('argument validation', () => {
|
|
6
|
-
expect(parse.bind()).toThrowError(/argument str must be a string/)
|
|
7
|
-
expect(parse.bind(null, 42)).toThrowError(/argument str must be a string/)
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('basic', () => {
|
|
11
|
-
expect(parse('foo=bar')).toEqual({ foo: 'bar' })
|
|
12
|
-
expect(parse('foo=123')).toEqual({ foo: '123' })
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('ignore spaces', () => {
|
|
16
|
-
expect(parse('FOO = bar; baz = raz')).toEqual({
|
|
17
|
-
FOO: 'bar',
|
|
18
|
-
baz: 'raz'
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('escaping', () => {
|
|
23
|
-
expect(parse('foo="bar=123456789&name=Magic+Mouse"')).toEqual({
|
|
24
|
-
foo: 'bar=123456789&name=Magic+Mouse'
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
expect(parse('email=%20%22%2c%3b%2f')).toEqual({ email: ' ",;/' })
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('ignore escaping error and return original value', () => {
|
|
31
|
-
expect(parse('foo=%1;bar=bar')).toEqual({ foo: '%1', bar: 'bar' })
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('ignore non values', () => {
|
|
35
|
-
expect(parse('foo=%1;bar=bar;HttpOnly;Secure')).toEqual({
|
|
36
|
-
foo: '%1',
|
|
37
|
-
bar: 'bar'
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('unencoded', () => {
|
|
42
|
-
expect(
|
|
43
|
-
parse('foo="bar=123456789&name=Magic+Mouse"', {
|
|
44
|
-
decode: function (v) {
|
|
45
|
-
return v
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
).toEqual({ foo: 'bar=123456789&name=Magic+Mouse' })
|
|
49
|
-
|
|
50
|
-
expect(
|
|
51
|
-
parse('email=%20%22%2c%3b%2f', {
|
|
52
|
-
decode: function (v) {
|
|
53
|
-
return v
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
).toEqual({ email: '%20%22%2c%3b%2f' })
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('dates', () => {
|
|
60
|
-
expect(
|
|
61
|
-
parse('priority=true; expires=Wed, 29 Jan 2014 17:43:25 GMT; Path=/', {
|
|
62
|
-
decode: function (v) {
|
|
63
|
-
return v
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
).toEqual({
|
|
67
|
-
priority: 'true',
|
|
68
|
-
Path: '/',
|
|
69
|
-
expires: 'Wed, 29 Jan 2014 17:43:25 GMT'
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('missing value', () => {
|
|
74
|
-
expect(
|
|
75
|
-
parse('foo; bar=1; fizz= ; buzz=2', {
|
|
76
|
-
decode: function (v) {
|
|
77
|
-
return v
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
).toEqual({ bar: '1', fizz: '', buzz: '2' })
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('assign only once', () => {
|
|
84
|
-
expect(parse('foo=%1;bar=bar;foo=boo')).toEqual({ foo: '%1', bar: 'bar' })
|
|
85
|
-
expect(parse('foo=false;bar=bar;foo=true'), {
|
|
86
|
-
foo: 'false',
|
|
87
|
-
bar: 'bar'
|
|
88
|
-
})
|
|
89
|
-
expect(parse('foo=;bar=bar;foo=boo')).toEqual({ foo: '', bar: 'bar' })
|
|
90
|
-
})
|
|
91
|
-
})
|
package/spec/serialize.spec.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import cookie from '../src/index.js'
|
|
3
|
-
|
|
4
|
-
describe('Cookie Serialize', () => {
|
|
5
|
-
it('basic', () => {
|
|
6
|
-
expect(cookie.serialize('foo', 'bar')).toEqual('foo=bar')
|
|
7
|
-
expect(cookie.serialize('foo', 'bar baz')).toEqual('foo=bar%20baz')
|
|
8
|
-
expect(cookie.serialize('foo', '')).toEqual('foo=')
|
|
9
|
-
expect(cookie.serialize.bind(cookie, 'foo\n', 'bar')).toThrowError(
|
|
10
|
-
/argument name is invalid/
|
|
11
|
-
)
|
|
12
|
-
expect(cookie.serialize.bind(cookie, 'foo\u280a', 'bar')).toThrowError(
|
|
13
|
-
/argument name is invalid/
|
|
14
|
-
)
|
|
15
|
-
expect(
|
|
16
|
-
cookie.serialize.bind(cookie, 'foo', 'bar', { encode: 42 })
|
|
17
|
-
).toThrowError(/option encode is invalid/)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('path', () => {
|
|
21
|
-
expect(cookie.serialize('foo', 'bar', { path: '/' })).toEqual(
|
|
22
|
-
'foo=bar; Path=/'
|
|
23
|
-
)
|
|
24
|
-
expect(
|
|
25
|
-
cookie.serialize.bind(cookie, 'foo', 'bar', {
|
|
26
|
-
path: '/\n'
|
|
27
|
-
})
|
|
28
|
-
).toThrowError(/option path is invalid/)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('secure', () => {
|
|
32
|
-
expect(cookie.serialize('foo', 'bar', { secure: true })).toEqual(
|
|
33
|
-
'foo=bar; Secure'
|
|
34
|
-
)
|
|
35
|
-
expect(cookie.serialize('foo', 'bar', { secure: false })).toEqual('foo=bar')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('domain', () => {
|
|
39
|
-
expect(cookie.serialize('foo', 'bar', { domain: 'example.com' })).toEqual(
|
|
40
|
-
'foo=bar; Domain=example.com'
|
|
41
|
-
)
|
|
42
|
-
expect(
|
|
43
|
-
cookie.serialize.bind(cookie, 'foo', 'bar', {
|
|
44
|
-
domain: 'example.com\n'
|
|
45
|
-
})
|
|
46
|
-
).toThrowError(/option domain is invalid/)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('httpOnly', () => {
|
|
50
|
-
expect(cookie.serialize('foo', 'bar', { httpOnly: true })).toEqual(
|
|
51
|
-
'foo=bar; HttpOnly'
|
|
52
|
-
)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('maxAge', () => {
|
|
56
|
-
expect(() =>
|
|
57
|
-
cookie.serialize('foo', 'bar', {
|
|
58
|
-
maxAge: 'buzz'
|
|
59
|
-
})
|
|
60
|
-
).toThrowError(/option maxAge is invalid/)
|
|
61
|
-
|
|
62
|
-
expect(() =>
|
|
63
|
-
cookie.serialize('foo', 'bar', {
|
|
64
|
-
maxAge: Infinity
|
|
65
|
-
})
|
|
66
|
-
).toThrowError(/option maxAge is invalid/)
|
|
67
|
-
|
|
68
|
-
expect(cookie.serialize('foo', 'bar', { maxAge: 1000 })).toEqual(
|
|
69
|
-
'foo=bar; Max-Age=1000'
|
|
70
|
-
)
|
|
71
|
-
expect(cookie.serialize('foo', 'bar', { maxAge: '1000' })).toEqual(
|
|
72
|
-
'foo=bar; Max-Age=1000'
|
|
73
|
-
)
|
|
74
|
-
expect(cookie.serialize('foo', 'bar', { maxAge: 0 })).toEqual(
|
|
75
|
-
'foo=bar; Max-Age=0'
|
|
76
|
-
)
|
|
77
|
-
expect(cookie.serialize('foo', 'bar', { maxAge: '0' })).toEqual(
|
|
78
|
-
'foo=bar; Max-Age=0'
|
|
79
|
-
)
|
|
80
|
-
expect(cookie.serialize('foo', 'bar', { maxAge: null })).toEqual('foo=bar')
|
|
81
|
-
expect(cookie.serialize('foo', 'bar', { maxAge: undefined })).toEqual(
|
|
82
|
-
'foo=bar'
|
|
83
|
-
)
|
|
84
|
-
expect(cookie.serialize('foo', 'bar', { maxAge: 3.14 })).toEqual(
|
|
85
|
-
'foo=bar; Max-Age=3'
|
|
86
|
-
)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('expires', () => {
|
|
90
|
-
expect(
|
|
91
|
-
cookie.serialize('foo', 'bar', {
|
|
92
|
-
expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900))
|
|
93
|
-
})
|
|
94
|
-
).toEqual('foo=bar; Expires=Sun, 24 Dec 2000 10:30:59 GMT')
|
|
95
|
-
|
|
96
|
-
expect(
|
|
97
|
-
cookie.serialize.bind(cookie, 'foo', 'bar', {
|
|
98
|
-
expires: Date.now()
|
|
99
|
-
})
|
|
100
|
-
).toThrowError(/option expires is invalid/)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('sameSite', () => {
|
|
104
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: true })).toEqual(
|
|
105
|
-
'foo=bar; SameSite=Strict'
|
|
106
|
-
)
|
|
107
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: 'Strict' })).toEqual(
|
|
108
|
-
'foo=bar; SameSite=Strict'
|
|
109
|
-
)
|
|
110
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: 'strict' })).toEqual(
|
|
111
|
-
'foo=bar; SameSite=Strict'
|
|
112
|
-
)
|
|
113
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: 'Lax' })).toEqual(
|
|
114
|
-
'foo=bar; SameSite=Lax'
|
|
115
|
-
)
|
|
116
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: 'lax' })).toEqual(
|
|
117
|
-
'foo=bar; SameSite=Lax'
|
|
118
|
-
)
|
|
119
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: 'None' })).toEqual(
|
|
120
|
-
'foo=bar; SameSite=None'
|
|
121
|
-
)
|
|
122
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: 'none' })).toEqual(
|
|
123
|
-
'foo=bar; SameSite=None'
|
|
124
|
-
)
|
|
125
|
-
expect(cookie.serialize('foo', 'bar', { sameSite: false })).toEqual(
|
|
126
|
-
'foo=bar'
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
expect(
|
|
130
|
-
cookie.serialize.bind(cookie, 'foo', 'bar', {
|
|
131
|
-
sameSite: 'foo'
|
|
132
|
-
})
|
|
133
|
-
).toThrowError(/option sameSite is invalid/)
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
it('escaping', () => {
|
|
137
|
-
expect(cookie.serialize('cat', '+ ')).toEqual('cat=%2B%20')
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('parse->serialize', () => {
|
|
141
|
-
expect(
|
|
142
|
-
cookie.parse(cookie.serialize('cat', 'foo=123&name=baz five'))
|
|
143
|
-
).toEqual({
|
|
144
|
-
cat: 'foo=123&name=baz five'
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
expect(cookie.parse(cookie.serialize('cat', ' ";/'))).toEqual({
|
|
148
|
-
cat: ' ";/'
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it('unencoded', () => {
|
|
153
|
-
expect(
|
|
154
|
-
cookie.serialize('cat', '+ ', {
|
|
155
|
-
encode: function (value) {
|
|
156
|
-
return value
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
).toEqual('cat=+ ')
|
|
160
|
-
|
|
161
|
-
expect(
|
|
162
|
-
cookie.serialize.bind(cookie, 'cat', '+ \n', {
|
|
163
|
-
encode: function (value) {
|
|
164
|
-
return value
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
).toThrowError(/argument val is invalid/)
|
|
168
|
-
})
|
|
169
|
-
})
|
package/tsconfig.json
DELETED