@@ -4,7 +4,6 @@ const { collectASequenceOfCodePointsFast } = require('../infra')
44const { maxNameValuePairSize, maxAttributeValueSize } = require ( './constants' )
55const { isCTLExcludingHtab } = require ( './util' )
66const assert = require ( 'node:assert' )
7- const { unescape : qsUnescape } = require ( 'node:querystring' )
87
98/**
109 * @description Parses the field-value attributes of a set-cookie header string.
@@ -82,7 +81,7 @@ function parseSetCookie (header) {
8281 // store arbitrary data in a cookie-value SHOULD encode that data, for
8382 // example, using Base64 [RFC4648].
8483 return {
85- name, value : qsUnescape ( value ) , ...parseUnparsedAttributes ( unparsedAttributes )
84+ name, value, ...parseUnparsedAttributes ( unparsedAttributes )
8685 }
8786}
8887
@@ -280,32 +279,25 @@ function parseUnparsedAttributes (unparsedAttributes, cookieAttributeList = {})
280279 // If the attribute-name case-insensitively matches the string
281280 // "SameSite", the user agent MUST process the cookie-av as follows:
282281
283- // 1. Let enforcement be "Default".
284- let enforcement = 'Default'
285-
286282 const attributeValueLowercase = attributeValue . toLowerCase ( )
287- // 2. If cookie-av's attribute-value is a case-insensitive match for
288- // "None", set enforcement to "None".
289- if ( attributeValueLowercase . includes ( 'none' ) ) {
290- enforcement = 'None'
291- }
292283
293- // 3. If cookie-av's attribute-value is a case-insensitive match for
294- // "Strict", set enforcement to "Strict".
295- if ( attributeValueLowercase . includes ( 'strict' ) ) {
296- enforcement = 'Strict'
284+ // 1. If cookie-av's attribute-value is a case-insensitive match for
285+ // "None", append an attribute to the cookie-attribute-list with an
286+ // attribute-name of "SameSite" and an attribute-value of "None".
287+ if ( attributeValueLowercase === 'none' ) {
288+ cookieAttributeList . sameSite = 'None'
289+ } else if ( attributeValueLowercase === 'strict' ) {
290+ // 2. If cookie-av's attribute-value is a case-insensitive match for
291+ // "Strict", append an attribute to the cookie-attribute-list with
292+ // an attribute-name of "SameSite" and an attribute-value of
293+ // "Strict".
294+ cookieAttributeList . sameSite = 'Strict'
295+ } else if ( attributeValueLowercase === 'lax' ) {
296+ // 3. If cookie-av's attribute-value is a case-insensitive match for
297+ // "Lax", append an attribute to the cookie-attribute-list with an
298+ // attribute-name of "SameSite" and an attribute-value of "Lax".
299+ cookieAttributeList . sameSite = 'Lax'
297300 }
298-
299- // 4. If cookie-av's attribute-value is a case-insensitive match for
300- // "Lax", set enforcement to "Lax".
301- if ( attributeValueLowercase . includes ( 'lax' ) ) {
302- enforcement = 'Lax'
303- }
304-
305- // 5. Append an attribute to the cookie-attribute-list with an
306- // attribute-name of "SameSite" and an attribute-value of
307- // enforcement.
308- cookieAttributeList . sameSite = enforcement
309301 } else {
310302 cookieAttributeList . unparsed ??= [ ]
311303
0 commit comments