mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
raise error if value contains CR/LF in iniheader of initialize_http_header
like r59693, initialize_http_header also should raise error. [Bug #14208] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
677c539d1f
commit
0078e40115
2 changed files with 22 additions and 3 deletions
|
@ -18,7 +18,11 @@ module Net::HTTPHeader
|
||||||
if value.nil?
|
if value.nil?
|
||||||
warn "net/http: nil HTTP header: #{key}", uplevel: 1 if $VERBOSE
|
warn "net/http: nil HTTP header: #{key}", uplevel: 1 if $VERBOSE
|
||||||
else
|
else
|
||||||
@header[key.downcase] = [value.strip]
|
value = value.strip # raise error for invalid byte sequences
|
||||||
|
if value.count("\r\n") > 0
|
||||||
|
raise ArgumentError, 'header field value cannot include CR/LF'
|
||||||
|
end
|
||||||
|
@header[key.downcase] = [value]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -75,8 +79,8 @@ module Net::HTTPHeader
|
||||||
append_field_value(ary, val)
|
append_field_value(ary, val)
|
||||||
@header[key.downcase] = ary
|
@header[key.downcase] = ary
|
||||||
else
|
else
|
||||||
val = val.to_s
|
val = val.to_s # for compatibility use to_s instead of to_str
|
||||||
if /[\r\n]/n.match?(val.b)
|
if val.b.count("\r\n") > 0
|
||||||
raise ArgumentError, 'header field value cannot include CR/LF'
|
raise ArgumentError, 'header field value cannot include CR/LF'
|
||||||
end
|
end
|
||||||
@header[key.downcase] = [val]
|
@header[key.downcase] = [val]
|
||||||
|
|
|
@ -16,6 +16,21 @@ class HTTPHeaderTest < Test::Unit::TestCase
|
||||||
@c = C.new
|
@c = C.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_initialize
|
||||||
|
@c.initialize_http_header("foo"=>"abc")
|
||||||
|
assert_equal "abc", @c["foo"]
|
||||||
|
@c.initialize_http_header("foo"=>"abc", "bar"=>"xyz")
|
||||||
|
assert_equal "xyz", @c["bar"]
|
||||||
|
@c.initialize_http_header([["foo", "abc"]])
|
||||||
|
assert_equal "abc", @c["foo"]
|
||||||
|
@c.initialize_http_header([["foo", "abc"], ["bar","xyz"]])
|
||||||
|
assert_equal "xyz", @c["bar"]
|
||||||
|
assert_raise(NoMethodError){ @c.initialize_http_header("foo"=>[]) }
|
||||||
|
assert_raise(ArgumentError){ @c.initialize_http_header("foo"=>"a\nb") }
|
||||||
|
assert_raise(ArgumentError){ @c.initialize_http_header("foo"=>"a\rb") }
|
||||||
|
assert_raise(ArgumentError){ @c.initialize_http_header("foo"=>"a\xff") }
|
||||||
|
end
|
||||||
|
|
||||||
def test_size
|
def test_size
|
||||||
assert_equal 0, @c.size
|
assert_equal 0, @c.size
|
||||||
@c['a'] = 'a'
|
@c['a'] = 'a'
|
||||||
|
|
Loading…
Add table
Reference in a new issue