Do not raise exception when content_type is a empty string

When content type header is blank we were raising an exception because
`empty?` was being called on nil.
This commit is contained in:
Rafael Mendonça França 2016-12-09 14:29:06 -05:00
parent a9d72f6e47
commit 4eb3ef812c
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 6 additions and 1 deletions

@ -408,7 +408,7 @@ def cookies
def parse_content_type(content_type)
if content_type
type, charset = content_type.split(/;\s*charset=/)
type = nil if type.empty?
type = nil if type && type.empty?
ContentTypeHeader.new(type, charset)
else
NullContentTypeHeader

@ -110,6 +110,11 @@ def test_setting_content_type_header_impacts_content_type_method
assert_equal "application/aaron", @response.content_type
end
def test_empty_content_type_returns_nil
@response.headers['Content-Type'] = ""
assert_equal nil, @response.content_type
end
test "simple output" do
@response.body = "Hello, World!"