[ruby/cgi] Relax domain label restrictions

https://github.com/ruby/cgi/commit/b46d41c363
This commit is contained in:
Nobuyoshi Nakada 2022-11-22 11:05:52 +09:00 committed by git
parent 5304b3bd85
commit 58682b6980
2 changed files with 19 additions and 1 deletions

View File

@ -42,7 +42,7 @@ class CGI
TOKEN_RE = %r"\A[[!-~]&&[^()<>@,;:\\\"/?=\[\]{}]]+\z"
PATH_VALUE_RE = %r"\A[[ -~]&&[^;]]*\z"
DOMAIN_VALUE_RE = %r"\A(?<label>[A-Za-z][-A-Za-z0-9]*[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.
#

View File

@ -60,6 +60,24 @@ class CGICookieTest < Test::Unit::TestCase
end
def test_cgi_cookie_new_with_domain
h = {'name'=>'name1', 'value'=>'value1'}
cookie = CGI::Cookie.new('domain'=>'a.example.com', **h)
assert_equal('a.example.com', cookie.domain)
cookie = CGI::Cookie.new('domain'=>'1.example.com', **h)
assert_equal('1.example.com', cookie.domain, 'enhanced by RFC 1123')
assert_raise(ArgumentError) {
CGI::Cookie.new('domain'=>'-a.example.com', **h)
}
assert_raise(ArgumentError) {
CGI::Cookie.new('domain'=>'a-.example.com', **h)
}
end
def test_cgi_cookie_scriptname
cookie = CGI::Cookie.new('name1', 'value1')
assert_equal('', cookie.path)