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

ruby-changes:47902

From: naruse <ko1@a...>
Date: Mon, 25 Sep 2017 23:28:57 +0900 (JST)
Subject: [ruby-changes:47902] naruse:r60021 (trunk): HTTPHeader#add_field should allow binary [Bug #13926]

naruse	2017-09-25 23:28:53 +0900 (Mon, 25 Sep 2017)

  New Revision: 60021

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

  Log:
    HTTPHeader#add_field should allow binary [Bug #13926]

  Modified files:
    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 60020)
+++ lib/net/http/header.rb	(revision 60021)
@@ -76,7 +76,7 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L76
       @header[key.downcase] = ary
     else
       val = val.to_s
-      if /[\r\n]/.match?(val)
+      if /[\r\n]/n.match?(val.b)
         raise ArgumentError, 'header field value cannnot include CR/LF'
       end
       @header[key.downcase] = [val]
@@ -89,7 +89,7 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L89
       val.each{|x| append_field_value(ary, x)}
     else
       val = val.to_s
-      if /[\r\n]/.match?(val)
+      if /[\r\n]/n.match?(val.b)
         raise ArgumentError, 'header field value cannnot include CR/LF'
       end
       ary.push val
Index: test/net/http/test_httpheader.rb
===================================================================
--- test/net/http/test_httpheader.rb	(revision 60020)
+++ test/net/http/test_httpheader.rb	(revision 60021)
@@ -45,6 +45,9 @@ class HTTPHeaderTest < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L45
     assert_equal 2, @c.length
     assert_equal ['aaa', 'bbb', '3'], @c.get_fields('aaa')
 
+    @c['aaa'] = "aaa\xff"
+    assert_equal 2, @c.length
+
     assert_raise(ArgumentError){ @c['foo'] = "a\nb" }
     assert_raise(ArgumentError){ @c['foo'] = ["a\nb"] }
   end
@@ -73,9 +76,9 @@ class HTTPHeaderTest < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L76
     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')
+    @c.add_field 'My-Header', ['e', ["\xff", 7]]
+    assert_equal "a, b, c, d, d, e, \xff, 7", @c['My-Header']
+    assert_equal ['a', 'b', 'c', 'd, d', 'e', "\xff", '7'], @c.get_fields('My-Header')
   end
 
   def test_get_fields

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

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