File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff 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-z] [-A-Za-z0-9]*[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 #
Original file line number Diff line number Diff line change @@ -60,6 +60,24 @@ def test_cgi_cookie_new_complex
6060 end
6161
6262
63+ def test_cgi_cookie_new_with_domain
64+ h = { 'name' => 'name1' , 'value' => 'value1' }
65+ cookie = CGI ::Cookie . new ( 'domain' => 'a.example.com' , **h )
66+ assert_equal ( 'a.example.com' , cookie . domain )
67+
68+ cookie = CGI ::Cookie . new ( 'domain' => '1.example.com' , **h )
69+ assert_equal ( '1.example.com' , cookie . domain , 'enhanced by RFC 1123' )
70+
71+ assert_raise ( ArgumentError ) {
72+ CGI ::Cookie . new ( 'domain' => '-a.example.com' , **h )
73+ }
74+
75+ assert_raise ( ArgumentError ) {
76+ CGI ::Cookie . new ( 'domain' => 'a-.example.com' , **h )
77+ }
78+ end
79+
80+
6381 def test_cgi_cookie_scriptname
6482 cookie = CGI ::Cookie . new ( 'name1' , 'value1' )
6583 assert_equal ( '' , cookie . path )
You can’t perform that action at this time.
0 commit comments