зеркало из https://github.com/github/ruby.git
HTTPHeader#add_field should allow binary [Bug #13926]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
0c482713dd
Коммит
56f91c6ec5
|
@ -76,7 +76,7 @@ module Net::HTTPHeader
|
||||||
@header[key.downcase] = ary
|
@header[key.downcase] = ary
|
||||||
else
|
else
|
||||||
val = val.to_s
|
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'
|
raise ArgumentError, 'header field value cannnot include CR/LF'
|
||||||
end
|
end
|
||||||
@header[key.downcase] = [val]
|
@header[key.downcase] = [val]
|
||||||
|
@ -89,7 +89,7 @@ module Net::HTTPHeader
|
||||||
val.each{|x| append_field_value(ary, x)}
|
val.each{|x| append_field_value(ary, x)}
|
||||||
else
|
else
|
||||||
val = val.to_s
|
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'
|
raise ArgumentError, 'header field value cannnot include CR/LF'
|
||||||
end
|
end
|
||||||
ary.push val
|
ary.push val
|
||||||
|
|
|
@ -45,6 +45,9 @@ class HTTPHeaderTest < Test::Unit::TestCase
|
||||||
assert_equal 2, @c.length
|
assert_equal 2, @c.length
|
||||||
assert_equal ['aaa', 'bbb', '3'], @c.get_fields('aaa')
|
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" }
|
||||||
assert_raise(ArgumentError){ @c['foo'] = ["a\nb"] }
|
assert_raise(ArgumentError){ @c['foo'] = ["a\nb"] }
|
||||||
end
|
end
|
||||||
|
@ -73,9 +76,9 @@ class HTTPHeaderTest < Test::Unit::TestCase
|
||||||
assert_equal 'a, b, c, d, d', @c['My-Header']
|
assert_equal 'a, b, c, d, d', @c['My-Header']
|
||||||
assert_equal ['a', 'b', 'c', 'd, d'], @c.get_fields('My-Header')
|
assert_equal ['a', 'b', 'c', 'd, d'], @c.get_fields('My-Header')
|
||||||
assert_raise(ArgumentError){ @c.add_field 'My-Header', "d\nd" }
|
assert_raise(ArgumentError){ @c.add_field 'My-Header', "d\nd" }
|
||||||
@c.add_field 'My-Header', ['e', ['f', 7]]
|
@c.add_field 'My-Header', ['e', ["\xff", 7]]
|
||||||
assert_equal 'a, b, c, d, d, e, f, 7', @c['My-Header']
|
assert_equal "a, b, c, d, d, e, \xff, 7", @c['My-Header']
|
||||||
assert_equal ['a', 'b', 'c', 'd, d', 'e', 'f', '7'], @c.get_fields('My-Header')
|
assert_equal ['a', 'b', 'c', 'd, d', 'e', "\xff", '7'], @c.get_fields('My-Header')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_get_fields
|
def test_get_fields
|
||||||
|
|
Загрузка…
Ссылка в новой задаче