@@ -301,7 +301,7 @@ export function stringifySetCookie(
301
301
throw new TypeError ( `argument name is invalid: ${ cookie . name } ` ) ;
302
302
}
303
303
304
- const value = enc ( cookie . value || "" ) ;
304
+ const value = cookie . value ? enc ( cookie . value ) : "" ;
305
305
306
306
if ( ! cookieValueRegExp . test ( value ) ) {
307
307
throw new TypeError ( `argument val is invalid: ${ cookie . value } ` ) ;
@@ -424,32 +424,34 @@ export function parseSetCookie(str: string, options?: ParseOptions): SetCookie {
424
424
eqIdx === - 1
425
425
? valueSlice ( str , index , endIdx )
426
426
: valueSlice ( str , index , eqIdx ) ;
427
- const name = attr . toLowerCase ( ) ;
427
+ const val = eqIdx === - 1 ? undefined : valueSlice ( str , eqIdx + 1 , endIdx ) ;
428
428
429
- // Handle boolean attributes.
430
- if ( eqIdx === - 1 ) {
431
- if ( name === "httponly" ) {
429
+ switch ( attr . toLowerCase ( ) ) {
430
+ case "httponly" :
432
431
setCookie . httpOnly = true ;
433
- } else if ( name === "secure" ) {
432
+ break ;
433
+ case "secure" :
434
434
setCookie . secure = true ;
435
- } else if ( name === "partitioned" ) {
435
+ break ;
436
+ case "partitioned" :
436
437
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" :
444
440
setCookie . domain = val ;
445
- } else if ( name === "path" ) {
441
+ break ;
442
+ case "path" :
446
443
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 ;
448
450
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 ;
453
455
const priority = val . toLowerCase ( ) ;
454
456
if (
455
457
priority === "low" ||
@@ -458,7 +460,9 @@ export function parseSetCookie(str: string, options?: ParseOptions): SetCookie {
458
460
) {
459
461
setCookie . priority = priority ;
460
462
}
461
- } else if ( name === "samesite" ) {
463
+ break ;
464
+ case "samesite" :
465
+ if ( ! val ) break ;
462
466
const sameSite = val . toLowerCase ( ) ;
463
467
if (
464
468
sameSite === "lax" ||
@@ -467,7 +471,7 @@ export function parseSetCookie(str: string, options?: ParseOptions): SetCookie {
467
471
) {
468
472
setCookie . sameSite = sameSite ;
469
473
}
470
- }
474
+ break ;
471
475
}
472
476
473
477
index = endIdx + 1 ;
0 commit comments