Skip to content

Commit

Permalink
Allow leading dot for domain (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey authored Oct 3, 2024
1 parent 58015c0 commit 6a8b8f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit 6a8b8f5

Please # to comment.