Skip to content

Commit

Permalink
Loosen the domain regex to accept '.' (#29)
Browse files Browse the repository at this point in the history
* Loosen the domain regex to accept '.'

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
  • Loading branch information
3 people committed Nov 28, 2022
1 parent 17cbccd commit 5e09d63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cgi/cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Cookie < Array

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

# Create a new CGI::Cookie object.
#
Expand Down
3 changes: 3 additions & 0 deletions test/cgi/test_cgi_cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def test_cgi_cookie_new_with_domain
cookie = CGI::Cookie.new(h.merge('domain'=>'a.example.com'))
assert_equal('a.example.com', cookie.domain)

cookie = CGI::Cookie.new(h.merge('domain'=>'.example.com'))
assert_equal('.example.com', cookie.domain)

cookie = CGI::Cookie.new(h.merge('domain'=>'1.example.com'))
assert_equal('1.example.com', cookie.domain, 'enhanced by RFC 1123')

Expand Down

0 comments on commit 5e09d63

Please sign in to comment.