diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb index d6f12956..a3b67100 100644 --- a/lib/net/http/header.rb +++ b/lib/net/http/header.rb @@ -800,6 +800,7 @@ def type_params list = self['Content-Type'].to_s.split(';') list.shift list.each do |param| + next if param.strip.empty? k, v = *param.split('=', 2) result[k.strip] = v.strip end diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 590f8a2f..998f70df 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -1447,6 +1447,12 @@ def test_response_body_encoding_true_with_content_type assert_equal(Encoding::UTF_8, res.body.encoding) end + def test_response_body_encoding_true_with_trailing_semicolon_in_content_type + res = fe_request(true, 'text/html; charset=utf-8; ') + assert_equal("hello\u1234", res.body) + assert_equal(Encoding::UTF_8, res.body.encoding) + end + def test_response_body_encoding_string_without_content_type res = fe_request('utf-8') assert_equal("hello\u1234", res.body) diff --git a/test/net/http/test_httpheader.rb b/test/net/http/test_httpheader.rb index b86d4868..6f6ce922 100644 --- a/test/net/http/test_httpheader.rb +++ b/test/net/http/test_httpheader.rb @@ -512,6 +512,10 @@ 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=utf-8; ' + assert_equal({'charset' => 'utf-8'}, @c.type_params) + @c['content-type'] = 'text/html;' + assert_equal({}, @c.type_params) end def test_set_content_type