Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/web/cookies/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function parseUnparsedAttributes (unparsedAttributes, cookieAttributeList = {})

// 2. If the remainder of attribute-value contains a non-DIGIT
// character, ignore the cookie-av.
if (!/^\d+$/.test(attributeValue)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the following changes to ensure closer adherence to the specifications.

Suggested change
if (!/^\d+$/.test(attributeValue)) {
if (/[^\d]/.test(attributeValue.slice(1))) {

if (!/^-?\d+$/.test(attributeValue)) {
return parseUnparsedAttributes(unparsedAttributes, cookieAttributeList)
}

Expand Down
15 changes: 14 additions & 1 deletion test/cookie/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,22 @@ test('Set-Cookie parser', () => {
name: 'Space',
value: 'Cat',
secure: true,
httpOnly: true
httpOnly: true,
maxAge: -1
}])

for (const maxAge of ['-', '--1', '-1a', '+1', '']) {
headers = new Headers({
'set-cookie': `Space=Cat; Secure; HttpOnly; Max-Age=${maxAge}`
})
assert.deepEqual(getSetCookies(headers), [{
name: 'Space',
value: 'Cat',
secure: true,
httpOnly: true
}])
}

headers = new Headers({
'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land'
})
Expand Down
Loading