Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BetterErrors::Middleware for Content-Type that includes non MIME-Type parts #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/better_errors/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def internal_call(env, id, method)
body = JSON.parse(request.body.read)
return invalid_csrf_token_json_response unless request.cookies[CSRF_TOKEN_COOKIE_NAME] == body['csrfToken']

return not_acceptable_json_response unless request.content_type == 'application/json'
return not_acceptable_json_response unless request.media_type == 'application/json'

response = @error_page.send("do_#{method}", body)
[200, { "Content-Type" => "application/json; charset=utf-8" }, [JSON.dump(response)]]
Expand Down
14 changes: 14 additions & 0 deletions spec/better_errors/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,20 @@ def initialize(message, original_exception = nil)
end
end

context 'when the Content-Type of the request is application/json; charset=utf-8' do
before do
request_env['CONTENT_TYPE'] = 'application/json; charset=utf-8'
end

it 'returns JSON containing the eval result' do
expect(error_page).to receive(:do_eval).and_return(prompt: '#', result: "much_stuff_here")
expect(json_body).to match(
'prompt' => '#',
'result' => 'much_stuff_here',
)
end
end

context 'when the Content-Type of the request is application/json' do
before do
request_env['HTTP_CONTENT_TYPE'] = 'application/json'
Expand Down