Skip to content

Commit 6a8b8f5

Browse files
authored
Allow leading dot for domain (#174)
1 parent 58015c0 commit 6a8b8f5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ var cookieValueRegExp = /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u00
6464
* <letter> = any one of the 52 alphabetic characters A through Z in
6565
* upper case and a through z in lower case
6666
* <digit> = any one of the ten digits 0 through 9
67+
*
68+
* Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
69+
*
70+
* > (Note that a leading %x2E ("."), if present, is ignored even though that
71+
* character is not permitted, but a trailing %x2E ("."), if present, will
72+
* cause the user agent to ignore the attribute.)
6773
*/
6874

69-
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;
75+
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;
7076

7177
/**
7278
* RegExp to match path-value in RFC 6265 sec 4.1.1

test/serialize.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ describe('cookie.serialize(name, value, options)', function () {
7676
var validDomains = [
7777
'example.com',
7878
'sub.example.com',
79+
'.example.com',
80+
'localhost',
81+
'.localhost',
7982
'my-site.org',
8083
'localhost'
8184
];
@@ -94,7 +97,6 @@ describe('cookie.serialize(name, value, options)', function () {
9497
'sub.example.com\u0000',
9598
'my site.org',
9699
'domain..com',
97-
'.example.com',
98100
'example.com; Path=/',
99101
'example.com /* inject a comment */'
100102
];

0 commit comments

Comments
 (0)