From 1358cccd52190df3c74bdd8970dbfb06ffc4ec72 Mon Sep 17 00:00:00 2001 From: kkarikos Date: Thu, 21 Nov 2024 22:28:02 +0200 Subject: [PATCH] fix: use default cookie decoder (#13037) Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- .changeset/plenty-oranges-count.md | 5 +++++ packages/kit/src/runtime/server/cookie.js | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .changeset/plenty-oranges-count.md diff --git a/.changeset/plenty-oranges-count.md b/.changeset/plenty-oranges-count.md new file mode 100644 index 000000000000..3031d3cc6f43 --- /dev/null +++ b/.changeset/plenty-oranges-count.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: do not override default cookie decoder to allow users to override the `cookie` library version diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js index ddefa847a432..f4442872fbeb 100644 --- a/packages/kit/src/runtime/server/cookie.js +++ b/packages/kit/src/runtime/server/cookie.js @@ -67,8 +67,7 @@ export function get_cookies(request, url, trailing_slash) { return c.value; } - const decoder = opts?.decode || decodeURIComponent; - const req_cookies = parse(header, { decode: decoder }); + const req_cookies = parse(header, { decode: opts?.decode }); const cookie = req_cookies[name]; // the decoded string or undefined // in development, if the cookie was set during this session with `cookies.set`, @@ -95,8 +94,7 @@ export function get_cookies(request, url, trailing_slash) { * @param {import('cookie').CookieParseOptions} opts */ getAll(opts) { - const decoder = opts?.decode || decodeURIComponent; - const cookies = parse(header, { decode: decoder }); + const cookies = parse(header, { decode: opts?.decode }); for (const c of Object.values(new_cookies)) { if (