Skip to content

Commit 5e09d63

Browse files
tubaxenornobuhsbt
authored
Loosen the domain regex to accept '.' (#29)
* Loosen the domain regex to accept '.' Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
1 parent 17cbccd commit 5e09d63

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/cgi/cookie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Cookie < Array
4242

4343
TOKEN_RE = %r"\A[[!-~]&&[^()<>@,;:\\\"/?=\[\]{}]]+\z"
4444
PATH_VALUE_RE = %r"\A[[ -~]&&[^;]]*\z"
45-
DOMAIN_VALUE_RE = %r"\A(?<label>(?!-)[-A-Za-z0-9]+(?<!-))(?:\.\g<label>)*\z"
45+
DOMAIN_VALUE_RE = %r"\A\.?(?<label>(?!-)[-A-Za-z0-9]+(?<!-))(?:\.\g<label>)*\z"
4646

4747
# Create a new CGI::Cookie object.
4848
#

test/cgi/test_cgi_cookie.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def test_cgi_cookie_new_with_domain
6565
cookie = CGI::Cookie.new(h.merge('domain'=>'a.example.com'))
6666
assert_equal('a.example.com', cookie.domain)
6767

68+
cookie = CGI::Cookie.new(h.merge('domain'=>'.example.com'))
69+
assert_equal('.example.com', cookie.domain)
70+
6871
cookie = CGI::Cookie.new(h.merge('domain'=>'1.example.com'))
6972
assert_equal('1.example.com', cookie.domain, 'enhanced by RFC 1123')
7073

0 commit comments

Comments
 (0)