@@ -301,7 +301,7 @@ export function stringifySetCookie(
301301 throw new TypeError ( `argument name is invalid: ${ cookie . name } ` ) ;
302302 }
303303
304- const value = enc ( cookie . value || "" ) ;
304+ const value = cookie . value ? enc ( cookie . value ) : "" ;
305305
306306 if ( ! cookieValueRegExp . test ( value ) ) {
307307 throw new TypeError ( `argument val is invalid: ${ cookie . value } ` ) ;
@@ -424,32 +424,34 @@ export function parseSetCookie(str: string, options?: ParseOptions): SetCookie {
424424 eqIdx === - 1
425425 ? valueSlice ( str , index , endIdx )
426426 : valueSlice ( str , index , eqIdx ) ;
427- const name = attr . toLowerCase ( ) ;
427+ const val = eqIdx === - 1 ? undefined : valueSlice ( str , eqIdx + 1 , endIdx ) ;
428428
429- // Handle boolean attributes.
430- if ( eqIdx === - 1 ) {
431- if ( name === "httponly" ) {
429+ switch ( attr . toLowerCase ( ) ) {
430+ case "httponly" :
432431 setCookie . httpOnly = true ;
433- } else if ( name === "secure" ) {
432+ break ;
433+ case "secure" :
434434 setCookie . secure = true ;
435- } else if ( name === "partitioned" ) {
435+ break ;
436+ case "partitioned" :
436437 setCookie . partitioned = true ;
437- }
438- } else {
439- const val = valueSlice ( str , eqIdx + 1 , endIdx ) ;
440-
441- if ( name === "max-age" ) {
442- if ( maxAgeRegExp . test ( val ) ) setCookie . maxAge = Number ( val ) ;
443- } else if ( name === "domain" ) {
438+ break ;
439+ case "domain" :
444440 setCookie . domain = val ;
445- } else if ( name === "path" ) {
441+ break ;
442+ case "path" :
446443 setCookie . path = val ;
447- } else if ( name === "expires" ) {
444+ break ;
445+ case "max-age" :
446+ if ( val && maxAgeRegExp . test ( val ) ) setCookie . maxAge = Number ( val ) ;
447+ break ;
448+ case "expires" :
449+ if ( ! val ) break ;
448450 const date = new Date ( val ) ;
449- if ( Number . isFinite ( date . valueOf ( ) ) ) {
450- setCookie . expires = date ;
451- }
452- } else if ( name === "priority" ) {
451+ if ( Number . isFinite ( date . valueOf ( ) ) ) setCookie . expires = date ;
452+ break ;
453+ case "priority" :
454+ if ( ! val ) break ;
453455 const priority = val . toLowerCase ( ) ;
454456 if (
455457 priority === "low" ||
@@ -458,7 +460,9 @@ export function parseSetCookie(str: string, options?: ParseOptions): SetCookie {
458460 ) {
459461 setCookie . priority = priority ;
460462 }
461- } else if ( name === "samesite" ) {
463+ break ;
464+ case "samesite" :
465+ if ( ! val ) break ;
462466 const sameSite = val . toLowerCase ( ) ;
463467 if (
464468 sameSite === "lax" ||
@@ -467,7 +471,7 @@ export function parseSetCookie(str: string, options?: ParseOptions): SetCookie {
467471 ) {
468472 setCookie . sameSite = sameSite ;
469473 }
470- }
474+ break ;
471475 }
472476
473477 index = endIdx + 1 ;
0 commit comments