@@ -237,6 +237,51 @@ describe("cookie-utils parseSetCookieHeader", () => {
237237 expect ( map . get ( "token" ) ?. value ) . toBe ( "abc" ) ;
238238 expect ( map . get ( "token" ) ?. expires ) . toBeUndefined ( ) ;
239239 } ) ;
240+
241+ it ( "handles Expires when cookie value contains gmt substring" , ( ) => {
242+ const map = parseSetCookieHeader (
243+ "session_data=testsessiondata; Path=/; Expires=Mon, 02 Mar 2026 05:42:16 GMT; Max-Age=300; Secure; HttpOnly; SameSite=lax" ,
244+ ) ;
245+
246+ expect ( map . get ( "session_data" ) ?. value ) . toBe ( "testsessiondata" ) ;
247+ expect ( map . get ( "session_data" ) ?. expires ) . toEqual (
248+ new Date ( "Mon, 02 Mar 2026 05:42:16 GMT" ) ,
249+ ) ;
250+ } ) ;
251+
252+ it ( "handles non-standard Expires=0" , ( ) => {
253+ const map = parseSetCookieHeader ( "a=1; Expires=0, b=2" ) ;
254+ expect ( map . get ( "a" ) ?. value ) . toBe ( "1" ) ;
255+ expect ( map . get ( "b" ) ?. value ) . toBe ( "2" ) ;
256+ } ) ;
257+
258+ it ( "handles RFC 850 date format" , ( ) => {
259+ const map = parseSetCookieHeader (
260+ "a=1; Expires=Sunday, 06-Nov-94 08:49:37 GMT, b=2" ,
261+ ) ;
262+ expect ( map . get ( "a" ) ?. value ) . toBe ( "1" ) ;
263+ expect ( map . get ( "b" ) ?. value ) . toBe ( "2" ) ;
264+ } ) ;
265+
266+ it ( "handles asctime date format (no comma in date)" , ( ) => {
267+ const map = parseSetCookieHeader (
268+ "a=1; Expires=Sun Nov 6 08:49:37 1994, b=2" ,
269+ ) ;
270+ expect ( map . get ( "a" ) ?. value ) . toBe ( "1" ) ;
271+ expect ( map . get ( "b" ) ?. value ) . toBe ( "2" ) ;
272+ } ) ;
273+
274+ it ( "handles mixed cookies with and without Expires" , ( ) => {
275+ const map = parseSetCookieHeader (
276+ "a=1; Path=/; HttpOnly, b=2; Expires=Mon, 01 Jan 2026 00:00:00 GMT; Secure, c=3; SameSite=Lax" ,
277+ ) ;
278+ expect ( map . get ( "a" ) ?. value ) . toBe ( "1" ) ;
279+ expect ( map . get ( "b" ) ?. value ) . toBe ( "2" ) ;
280+ expect ( map . get ( "b" ) ?. expires ) . toEqual (
281+ new Date ( "Mon, 01 Jan 2026 00:00:00 GMT" ) ,
282+ ) ;
283+ expect ( map . get ( "c" ) ?. value ) . toBe ( "3" ) ;
284+ } ) ;
240285} ) ;
241286
242287describe ( "cookie-utils stripSecureCookiePrefix" , ( ) => {
0 commit comments