Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow leading dot for domain #174

Merged
merged 2 commits into from
Oct 3, 2024
Merged
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
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ var cookieValueRegExp = /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u00
* <letter> = any one of the 52 alphabetic characters A through Z in
* upper case and a through z in lower case
* <digit> = any one of the ten digits 0 through 9
*
* Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
*
* > (Note that a leading %x2E ("."), if present, is ignored even though that
* character is not permitted, but a trailing %x2E ("."), if present, will
* cause the user agent to ignore the attribute.)
*/

var domainValueRegExp = /^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;

/**
* RegExp to match path-value in RFC 6265 sec 4.1.1
Expand Down
4 changes: 3 additions & 1 deletion test/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ describe('cookie.serialize(name, value, options)', function () {
var validDomains = [
'example.com',
'sub.example.com',
'.example.com',
'localhost',
'.localhost',
'my-site.org',
'localhost'
];
Expand All @@ -94,7 +97,6 @@ describe('cookie.serialize(name, value, options)', function () {
'sub.example.com\u0000',
'my site.org',
'domain..com',
'.example.com',
'example.com; Path=/',
'example.com /* inject a comment */'
];
Expand Down
Loading