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

ruby-changes:47681

From: usa <ko1@a...>
Date: Sat, 9 Sep 2017 22:50:15 +0900 (JST)
Subject: [ruby-changes:47681] usa:r59797 (ruby_2_3): merge revision(s) 59693, 59695: [Backport #13852]

usa	2017-09-09 22:50:10 +0900 (Sat, 09 Sep 2017)

  New Revision: 59797

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

  Log:
    merge revision(s) 59693,59695: [Backport #13852]
    
    A HTTP Header value must not contain CR or LF.
    to_str -> to_s
    
    * lib/net/http/header.rb (set_field): `val` can not have `to_str`.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/lib/net/http/header.rb
    branches/ruby_2_3/test/net/http/test_httpheader.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 59796)
+++ ruby_2_3/version.h	(revision 59797)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.5"
 #define RUBY_RELEASE_DATE "2017-09-09"
-#define RUBY_PATCHLEVEL 365
+#define RUBY_PATCHLEVEL 366
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 9
Index: ruby_2_3/test/net/http/test_httpheader.rb
===================================================================
--- ruby_2_3/test/net/http/test_httpheader.rb	(revision 59796)
+++ ruby_2_3/test/net/http/test_httpheader.rb	(revision 59797)
@@ -40,6 +40,13 @@ class HTTPHeaderTest < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/net/http/test_httpheader.rb#L40
     @c['aaA'] = 'aaa'
     @c['AAa'] = 'aaa'
     assert_equal 2, @c.length
+
+    @c['aaa'] = ['aaa', ['bbb', [3]]]
+    assert_equal 2, @c.length
+    assert_equal ['aaa', 'bbb', '3'], @c.get_fields('aaa')
+
+    assert_raise(ArgumentError){ @c['foo'] = "a\nb" }
+    assert_raise(ArgumentError){ @c['foo'] = ["a\nb"] }
   end
 
   def test_AREF
@@ -65,6 +72,10 @@ class HTTPHeaderTest < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/net/http/test_httpheader.rb#L72
     @c.add_field 'My-Header', 'd, d'
     assert_equal 'a, b, c, d, d', @c['My-Header']
     assert_equal ['a', 'b', 'c', 'd, d'], @c.get_fields('My-Header')
+    assert_raise(ArgumentError){ @c.add_field 'My-Header', "d\nd" }
+    @c.add_field 'My-Header', ['e', ['f', 7]]
+    assert_equal 'a, b, c, d, d, e, f, 7', @c['My-Header']
+    assert_equal ['a', 'b', 'c', 'd, d', 'e', 'f', '7'], @c.get_fields('My-Header')
   end
 
   def test_get_fields
Index: ruby_2_3/lib/net/http/header.rb
===================================================================
--- ruby_2_3/lib/net/http/header.rb	(revision 59796)
+++ ruby_2_3/lib/net/http/header.rb	(revision 59797)
@@ -38,7 +38,7 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/net/http/header.rb#L38
       @header.delete key.downcase
       return val
     end
-    @header[key.downcase] = [val]
+    set_field(key, val)
   end
 
   # [Ruby 1.8.3]
@@ -58,12 +58,40 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/net/http/header.rb#L58
   #
   def add_field(key, val)
     if @header.key?(key.downcase)
-      @header[key.downcase].push val
+      append_field_value(@header[key.downcase], val)
     else
+      set_field(key, val)
+    end
+  end
+
+  private def set_field(key, val)
+    case val
+    when Enumerable
+      ary = []
+      append_field_value(ary, val)
+      @header[key.downcase] = ary
+    else
+      val = val.to_s
+      if /[\r\n]/ =~ val
+        raise ArgumentError, 'header field value cannnot include CR/LF'
+      end
       @header[key.downcase] = [val]
     end
   end
 
+  private def append_field_value(ary, val)
+    case val
+    when Enumerable
+      val.each{|x| append_field_value(ary, x)}
+    else
+      val = val.to_s
+      if /[\r\n]/ =~ val
+        raise ArgumentError, 'header field value cannnot include CR/LF'
+      end
+      ary.push val
+    end
+  end
+
   # [Ruby 1.8.3]
   # Returns an array of header field strings corresponding to the
   # case-insensitive +key+.  This method allows you to get duplicated
Index: ruby_2_3
===================================================================
--- ruby_2_3	(revision 59796)
+++ ruby_2_3	(revision 59797)

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r59693,59695

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

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