[前][次][番号順一覧][スレッド一覧]

ruby-changes:41605

From: hsbt <ko1@a...>
Date: Fri, 29 Jan 2016 10:45:06 +0900 (JST)
Subject: [ruby-changes:41605] hsbt:r53679 (trunk): * lib/net/http/header.rb: Warn nil variable on HTTP Header.

hsbt	2016-01-29 10:46:02 +0900 (Fri, 29 Jan 2016)

  New Revision: 53679

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53679

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http/header.rb
    trunk/test/net/http/test_httpheader.rb
Index: lib/net/http/header.rb
===================================================================
--- lib/net/http/header.rb	(revision 53678)
+++ lib/net/http/header.rb	(revision 53679)
@@ -15,7 +15,11 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L15
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L454
   private :tokens
 
 end
-
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53678)
+++ ChangeLog	(revision 53679)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jan 29 10:44:56 2016  SHIBATA Hiroshi  <hsbt@r...>
+
+	* 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@r...>
 
 	* ext/socket/socket.c (sock_gethostname): support unlimited size
Index: test/net/http/test_httpheader.rb
===================================================================
--- test/net/http/test_httpheader.rb	(revision 53678)
+++ test/net/http/test_httpheader.rb	(revision 53679)
@@ -82,6 +82,12 @@ class HTTPHeaderTest < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L82
     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']

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]