1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
hsbt 2016-01-29 01:46:02 +00:00
parent 0897a6df5e
commit 809d3770e6
3 changed files with 17 additions and 2 deletions

View file

@ -1,3 +1,9 @@
Fri Jan 29 10:44:56 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* 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 <nobu@ruby-lang.org> Thu Jan 28 17:31:43 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/socket/socket.c (sock_gethostname): support unlimited size * ext/socket/socket.c (sock_gethostname): support unlimited size

View file

@ -15,7 +15,11 @@ module Net::HTTPHeader
return unless initheader return unless initheader
initheader.each do |key, value| initheader.each do |key, value|
warn "net/http: warning: duplicated HTTP header: #{key}" if key?(key) and $VERBOSE 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
end end
@ -450,4 +454,3 @@ module Net::HTTPHeader
private :tokens private :tokens
end end

View file

@ -82,6 +82,12 @@ class HTTPHeaderTest < Test::Unit::TestCase
assert_equal ['test string'], @c.get_fields('my-header') assert_equal ['test string'], @c.get_fields('my-header')
end 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 def test_delete
@c['My-Header'] = 'test' @c['My-Header'] = 'test'
assert_equal 'test', @c['My-Header'] assert_equal 'test', @c['My-Header']