@sveltejs/kit 1.0.0-next.556 → 1.0.0-next.557
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/package.json +1 -1
- package/src/runtime/server/cookie.js +12 -7
package/package.json
CHANGED
|
@@ -8,6 +8,10 @@ import { has_data_suffix, normalize_path, strip_data_suffix } from '../../utils/
|
|
|
8
8
|
* @type {Record<string, Set<string>>} */
|
|
9
9
|
const cookie_paths = {};
|
|
10
10
|
|
|
11
|
+
// default encoding functions for header cookie values
|
|
12
|
+
const encode = encodeURIComponent;
|
|
13
|
+
const decode = decodeURIComponent;
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
16
|
* @param {Request} request
|
|
13
17
|
* @param {URL} url
|
|
@@ -16,7 +20,7 @@ const cookie_paths = {};
|
|
|
16
20
|
*/
|
|
17
21
|
export function get_cookies(request, url, dev, trailing_slash) {
|
|
18
22
|
const header = request.headers.get('cookie') ?? '';
|
|
19
|
-
const initial_cookies = parse(header);
|
|
23
|
+
const initial_cookies = parse(header, { decode });
|
|
20
24
|
|
|
21
25
|
const normalized_url = normalize_path(
|
|
22
26
|
// Remove suffix: 'foo/__data.json' would mean the cookie path is '/foo',
|
|
@@ -76,8 +80,8 @@ export function get_cookies(request, url, dev, trailing_slash) {
|
|
|
76
80
|
return c.value;
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
const
|
|
80
|
-
const req_cookies = parse(header, { decode });
|
|
83
|
+
const decoder = opts?.decode || decode;
|
|
84
|
+
const req_cookies = parse(header, { decode: decoder });
|
|
81
85
|
const cookie = req_cookies[name]; // the decoded string or undefined
|
|
82
86
|
|
|
83
87
|
if (!dev || cookie) {
|
|
@@ -166,7 +170,7 @@ export function get_cookies(request, url, dev, trailing_slash) {
|
|
|
166
170
|
|
|
167
171
|
// cookies sent by the user agent have lowest precedence
|
|
168
172
|
for (const name in initial_cookies) {
|
|
169
|
-
combined_cookies[name] = initial_cookies[name];
|
|
173
|
+
combined_cookies[name] = encode(initial_cookies[name]);
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
// cookies previous set during this event with cookies.set have higher precedence
|
|
@@ -175,14 +179,15 @@ export function get_cookies(request, url, dev, trailing_slash) {
|
|
|
175
179
|
if (!domain_matches(destination.hostname, cookie.options.domain)) continue;
|
|
176
180
|
if (!path_matches(destination.pathname, cookie.options.path)) continue;
|
|
177
181
|
|
|
178
|
-
|
|
182
|
+
const encoder = cookie.options.encode || encode;
|
|
183
|
+
combined_cookies[cookie.name] = encoder(cookie.value);
|
|
179
184
|
}
|
|
180
185
|
|
|
181
186
|
// explicit header has highest precedence
|
|
182
187
|
if (header) {
|
|
183
|
-
const parsed = parse(header);
|
|
188
|
+
const parsed = parse(header, { decode });
|
|
184
189
|
for (const name in parsed) {
|
|
185
|
-
combined_cookies[name] = parsed[name];
|
|
190
|
+
combined_cookies[name] = encode(parsed[name]);
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
193
|
|