Fix NoMethodError when request Content-Type is blank.

This commit is contained in:
Bryan Traywick 2023-08-04 12:36:11 -04:00
parent a167350aca
commit a4633725d2
2 changed files with 8 additions and 1 deletions

View File

@ -163,7 +163,7 @@ module Mime
def lookup(string)
# fallback to the media-type without parameters if it was not found
LOOKUP[string] || LOOKUP[string.split(";", 2)[0].rstrip] || Type.new(string)
LOOKUP[string] || LOOKUP[string.split(";", 2)[0]&.rstrip] || Type.new(string)
end
def lookup_by_extension(extension)

View File

@ -607,6 +607,13 @@ class TestCaseTest < ActionController::TestCase
assert_equal "application/json", parsed_env["CONTENT_TYPE"]
end
test "blank Content-Type header" do
@request.headers["Content-Type"] = ""
assert_raises(ActionDispatch::Http::MimeNegotiation::InvalidType) do
get :test_headers
end
end
def test_using_as_json_sets_request_content_type_to_json
post :render_body, params: { bool_value: true, str_value: "string", num_value: 2 }, as: :json