Skip to content

Commit

Permalink
Fix NoMethodError when request Content-Type is blank.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryantraywick committed Aug 4, 2023
1 parent a167350 commit a463372
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/mime_type.rb
Expand Up @@ -163,7 +163,7 @@ def register_callback(&block)

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)
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/test_case_test.rb
Expand Up @@ -607,6 +607,13 @@ def test_params_passing_doesnt_modify_in_place
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

Expand Down

0 comments on commit a463372

Please sign in to comment.