Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_cgi_cookie_new_with_domain does not run in 2.6 or earlier #32

Open
headius opened this issue Nov 23, 2022 · 4 comments
Open

test_cgi_cookie_new_with_domain does not run in 2.6 or earlier #32

headius opened this issue Nov 23, 2022 · 4 comments

Comments

@headius
Copy link

headius commented Nov 23, 2022

The test added in 107a0c6 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)
@headius headius changed the title Test added does not run in 2.6 or earlier test_cgi_cookie_new_with_domain does not run in 2.6 or earlier Nov 23, 2022
headius added a commit to headius/cgi that referenced this issue Nov 23, 2022
2.6 cannot use kwargs **h to merge string-keyed hashes.

Fixes ruby#32
@headius
Copy link
Author

headius commented Nov 23, 2022

I pushed #33 to fix this, but there's a new issue: #34

@netsnipe
Copy link

netsnipe commented Dec 9, 2022

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

@netsnipe
Copy link

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

@headius
Copy link
Author

headius commented Jan 4, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants