From 809d3770e69e72913358d8da5e779d0334d4c5cb Mon Sep 17 00:00:00 2001 From: hsbt Date: Fri, 29 Jan 2016 01:46:02 +0000 Subject: [PATCH] * lib/net/http/header.rb: Warn nil variable on HTTP Header. It caused to NoMethodError. [fix GH-952][fix GH-641] Patch by @teosz * test/net/http/test_httpheader.rb: Added test for nil HTTP Header. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/net/http/header.rb | 7 +++++-- test/net/http/test_httpheader.rb | 6 ++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 30998cd327..06e25a7ecd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Jan 29 10:44:56 2016 SHIBATA Hiroshi + + * lib/net/http/header.rb: Warn nil variable on HTTP Header. + It caused to NoMethodError. [fix GH-952][fix GH-641] Patch by @teosz + * test/net/http/test_httpheader.rb: Added test for nil HTTP Header. + Thu Jan 28 17:31:43 2016 Nobuyoshi Nakada * ext/socket/socket.c (sock_gethostname): support unlimited size diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb index 3a76dcfe4c..30cdb70b91 100644 --- a/lib/net/http/header.rb +++ b/lib/net/http/header.rb @@ -15,7 +15,11 @@ module Net::HTTPHeader return unless initheader initheader.each do |key, value| warn "net/http: warning: duplicated HTTP header: #{key}" if key?(key) and $VERBOSE - @header[key.downcase] = [value.strip] + if value.nil? + warn "net/http: warning: nil HTTP header: #{key}" if $VERBOSE + else + @header[key.downcase] = [value.strip] + end end end @@ -450,4 +454,3 @@ module Net::HTTPHeader private :tokens end - diff --git a/test/net/http/test_httpheader.rb b/test/net/http/test_httpheader.rb index 2f3a0f1157..5f56816bcb 100644 --- a/test/net/http/test_httpheader.rb +++ b/test/net/http/test_httpheader.rb @@ -82,6 +82,12 @@ class HTTPHeaderTest < Test::Unit::TestCase assert_equal ['test string'], @c.get_fields('my-header') end + class D; include Net::HTTPHeader; end + + def test_nil_variable_header + assert_nothing_raised { D.new.initialize_http_header({Authorization: nil}) } + end + def test_delete @c['My-Header'] = 'test' assert_equal 'test', @c['My-Header']