diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb
index d6f12956..c6902f50 100644
--- a/lib/net/http/header.rb
+++ b/lib/net/http/header.rb
@@ -795,12 +795,16 @@ def sub_type
# res['content-type'] # => "application/json; charset=utf-8"
# res.type_params # => {"charset"=>"utf-8"}
#
+ # A parameter with no =, such as text/html; charset,
+ # is ignored. An empty value, such as charset=, is kept.
+ #
def type_params
result = {}
list = self['Content-Type'].to_s.split(';')
list.shift
list.each do |param|
- k, v = *param.split('=', 2)
+ k, v = param.split('=', 2)
+ next unless v
result[k.strip] = v.strip
end
result
diff --git a/test/net/http/test_httpheader.rb b/test/net/http/test_httpheader.rb
index b86d4868..bcda1c90 100644
--- a/test/net/http/test_httpheader.rb
+++ b/test/net/http/test_httpheader.rb
@@ -512,6 +512,12 @@ def test_type_params
assert_equal({'charset' => 'iso-2022-jp'}, @c.type_params)
@c.content_type = 'text'
assert_equal({}, @c.type_params)
+ @c.content_type = 'text/html; charset'
+ assert_equal({}, @c.type_params)
+ @c.content_type = 'text/html; charset; boundary=foo'
+ assert_equal({'boundary' => 'foo'}, @c.type_params)
+ @c.content_type = 'text/html; charset='
+ assert_equal({'charset' => ''}, @c.type_params)
end
def test_set_content_type
diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb
index 7c213f30..d0813707 100644
--- a/test/net/http/test_httpresponse.rb
+++ b/test/net/http/test_httpresponse.rb
@@ -382,6 +382,30 @@ def test_read_body_body_encoding_true_without_content_type_header
assert_equal Encoding::ASCII_8BIT, body.encoding
end
+ def test_read_body_body_encoding_true_with_valueless_content_type_parameter
+ body = "hello"
+ io = dummy_io(<