Skip to content

Commit e5603da

Browse files
CopilotRich-Harris
andcommitted
Format code and finalize cookie fix implementation
- Fix formatting issues with prettier - Verify all tests pass including edge cases - Confirm TypeScript type checking passes - Complete implementation addresses all review feedback from PR #14056 Co-authored-by: Rich-Harris <[email protected]>
1 parent ad4dc73 commit e5603da

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

packages/kit/src/runtime/server/cookie.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export function get_cookies(request, url) {
7777
// Try to get cookie using the unique key format if domain/path specified
7878
if (opts?.domain !== undefined || opts?.path !== undefined) {
7979
const cookie_key = generate_cookie_key(
80-
opts?.domain,
81-
opts?.path || url?.pathname || '/',
80+
opts?.domain,
81+
opts?.path || url?.pathname || '/',
8282
name
8383
);
8484
const c = new_cookies[cookie_key];
@@ -88,14 +88,17 @@ export function get_cookies(request, url) {
8888
return c.value;
8989
}
9090
}
91-
91+
9292
// Fallback: look for any cookie with this name that matches current domain/path
9393
// This maintains backward compatibility
9494
for (const key in new_cookies) {
9595
const c = new_cookies[key];
96-
if (c && c.name === name &&
96+
if (
97+
c &&
98+
c.name === name &&
9799
domain_matches(url.hostname, c.options.domain) &&
98-
path_matches(url.pathname, c.options.path)) {
100+
path_matches(url.pathname, c.options.path)
101+
) {
99102
return c.value;
100103
}
101104
}

packages/kit/src/runtime/server/cookie.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,36 +216,36 @@ test("set_internal isn't affected by defaults", () => {
216216

217217
test('reproduce issue #13947: multiple cookies with same name but different paths', () => {
218218
const { cookies } = cookies_setup();
219-
219+
220220
// Set two cookies with the same name but different paths
221221
cookies.set('key', 'value1', { path: '/foo' });
222222
cookies.set('key', 'value2', { path: '/bar' });
223-
223+
224224
// Both cookies should be accessible by specifying their path
225225
expect(cookies.get('key', { path: '/foo' })).toEqual('value1');
226226
expect(cookies.get('key', { path: '/bar' })).toEqual('value2');
227227
});
228228

229229
test('cookies with same name but different domains', () => {
230230
const { cookies } = cookies_setup();
231-
231+
232232
// Set two cookies with the same name but different domains
233233
cookies.set('key', 'value1', { path: '/', domain: 'example.com' });
234234
cookies.set('key', 'value2', { path: '/', domain: 'sub.example.com' });
235-
235+
236236
// Both cookies should be accessible by specifying their domain
237237
expect(cookies.get('key', { domain: 'example.com', path: '/' })).toEqual('value1');
238238
expect(cookies.get('key', { domain: 'sub.example.com', path: '/' })).toEqual('value2');
239239
});
240240

241241
test('cookies with same name but different domain and path combinations', () => {
242242
const { cookies } = cookies_setup();
243-
243+
244244
// Set cookies with same name but different domain/path combinations
245245
cookies.set('key', 'value1', { path: '/foo', domain: 'example.com' });
246246
cookies.set('key', 'value2', { path: '/bar', domain: 'example.com' });
247247
cookies.set('key', 'value3', { path: '/foo', domain: 'sub.example.com' });
248-
248+
249249
// All cookies should be accessible by specifying their domain and path
250250
expect(cookies.get('key', { domain: 'example.com', path: '/foo' })).toEqual('value1');
251251
expect(cookies.get('key', { domain: 'example.com', path: '/bar' })).toEqual('value2');
@@ -254,28 +254,28 @@ test('cookies with same name but different domain and path combinations', () =>
254254

255255
test('backward compatibility: get without domain/path options still works', () => {
256256
const { cookies } = cookies_setup();
257-
257+
258258
// Set a cookie the old way
259259
cookies.set('old-style', 'value', { path: '/' });
260-
260+
261261
// Should be retrievable without specifying path
262262
expect(cookies.get('old-style')).toEqual('value');
263263
});
264264

265265
test('get with only path specified (no domain)', () => {
266266
const { cookies } = cookies_setup();
267-
267+
268268
cookies.set('key', 'value', { path: '/test' });
269-
269+
270270
// Should be retrievable by path only
271271
expect(cookies.get('key', { path: '/test' })).toEqual('value');
272272
});
273273

274274
test('get with only domain specified (no path)', () => {
275275
const { cookies } = cookies_setup();
276-
276+
277277
cookies.set('key', 'value', { path: '/', domain: 'example.com' });
278-
278+
279279
// Should be retrievable by domain only (path defaults to current URL path)
280280
expect(cookies.get('key', { domain: 'example.com' })).toEqual('value');
281281
});

0 commit comments

Comments
 (0)