vercel / edge-runtime

Developing, testing, and defining the runtime Web APIs for Edge infrastructure.
https://edge-runtime.vercel.app
MIT License
820 stars 79 forks source link

cookie: `parseSetCookie` ignores `Max-Age` attribute #941

Open kosmotema opened 2 months ago

kosmotema commented 2 months ago

Bug Report

Current behavior

parseSetCookie ignores the Max-Age attribute when parsing a cookie. For example, this code:

import { parseSetCookie } from "@edge-runtime/cookies";

console.log(parseSetCookie("foo=bar; Max-Age=86400; Path=/; SameSite=none; HttpOnly; Secure"));

will output the following to the console:

{
  name: 'foo',
  value: 'bar',
  httpOnly: true,
  path: '/',
  sameSite: 'none',
  secure: true
}

Expected behavior/code

The above code sample should output:

{
  name: 'foo',
  value: 'bar',
  httpOnly: true,
  maxAge: 86400,
  path: '/',
  sameSite: 'none',
  secure: true
}

Possible solution

Since the Max-Age attribute (unlike the others) contains a hyphen in its name, here should be something like "max-age": maxage

sibiraj-s commented 3 weeks ago

Made a fix https://github.com/vercel/edge-runtime/pull/995