cgi
cgi copied to clipboard
test_cgi_cookie_new_with_domain does not run in 2.6 or earlier
The test added in 107a0c67f922044dc78e2fde94f991206267a6a0 contains a test that uses `*h to merge two string hashes. This does not work under Ruby 2.6 and earlier, making it impossible to test v0.1.0.2 on any Ruby 2.6-compatible implementation.
Error: test_cgi_cookie_new_with_domain(CGICookieTest): TypeError: hash key "name" is not a Symbol
/home/enebo/work/gems/cgi/test/cgi/test_cgi_cookie.rb:65:in `test_cgi_cookie_new_with_domain'
62:
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)
I pushed #33 to fix this, but there's a new issue: #34
Hi @headius, I'm in the process of backportingcgi-0.1.0.2
from ruby-2.7.7
into ruby 2.6.10p210 (2022-04-12 revision 67958)
(see attached patch) and I've also applied 9cab3c5 locally. Everything compiles fine, but I'm still getting the same unit test failure:
1) Error:
CGICookieTest#test_cgi_cookie_new_with_domain:
TypeError: hash key "name" is not a Symbol
/builddir/build/BUILD/ruby-2.6.10/test/cgi/test_cgi_cookie.rb:65:in `test_cgi_cookie_new_with_domain'
Are you able to advise else what I might be able to try or am potentially missing? Thanks.
ruby-2.7.7-Backport-CGI-0.1.0.2.patch.txt test_cgi_cookie.rb.txt
For anybody following, splatting the hashtable by hand is a quick and dirty workaround for ruby-2.6
--- a/test/cgi/test_cgi_cookie.rb 2022-12-13 10:42:11
+++ b/test/cgi/test_cgi_cookie.rb 2022-12-13 10:58:44
@@ -61,19 +61,26 @@
def test_cgi_cookie_new_with_domain
- h = {'name'=>'name1', 'value'=>'value1'}
- cookie = CGI::Cookie.new('domain'=>'a.example.com', **h)
+ cookie = CGI::Cookie.new('name'=>'name1',
+ 'value'=>'value1',
+ 'domain'=>'a.example.com')
assert_equal('a.example.com', cookie.domain)
- cookie = CGI::Cookie.new('domain'=>'1.example.com', **h)
+ cookie = CGI::Cookie.new('name'=>'name1',
+ 'value'=>'value1',
+ 'domain'=>'1.example.com')
assert_equal('1.example.com', cookie.domain, 'enhanced by RFC 1123')
assert_raise(ArgumentError) {
- CGI::Cookie.new('domain'=>'-a.example.com', **h)
+ CGI::Cookie.new('name'=>'name1',
+ 'value'=>'value1',
+ 'domain'=>'-a.example.com')
}
assert_raise(ArgumentError) {
- CGI::Cookie.new('domain'=>'a-.example.com', **h)
+ CGI::Cookie.new('name'=>'name1',
+ 'value'=>'value1',
+ 'domain'=>'a-.example.com')
}
end
@netsnipe Are you saying it works on Ruby 2.6 but not on JRuby? If so we'd need to fix something in JRuby, but this looks like the same issue as I fixed in #33 but perhaps somewhere else in the CGI library.