Commit c6a4c923 authored by Jan Provaznik's avatar Jan Provaznik

Use InvalidUTF8ErrorHandler only for rails 4

In Rails 5 catches invalid UTF8 characters in querystring in a
params middleware, errors are handled by a params middleware and
raises a BadRequest exception. This means that these UTF8 errors
are not raised deeper in application stack and these can't also
be handled on application level.

If we would want to have custom handler for these errors, we would
have to create a new middleware and insert it before actionpack's
params middleware and rescue BadRequest exceptions there. But there
is no need to do this currently (see discussion on
https://gitlab.com/gitlab-org/gitlab-ce/issues/51908)
parent 4127b357
......@@ -12,7 +12,9 @@ class ApplicationController < ActionController::Base
include WorkhorseHelper
include EnforcesTwoFactorAuthentication
include WithPerformanceBar
include InvalidUTF8ErrorHandler
# this can be removed after switching to rails 5
# https://gitlab.com/gitlab-org/gitlab-ce/issues/51908
include InvalidUTF8ErrorHandler unless Gitlab.rails5?
before_action :authenticate_sessionless_user!
before_action :authenticate_user!
......
......@@ -685,17 +685,28 @@ describe ApplicationController do
end
context 'html' do
subject { get :index, text: "hi \255" }
it 'renders 412' do
get :index, text: "hi \255"
if Gitlab.rails5?
expect { subject }.to raise_error(ActionController::BadRequest)
else
subject
expect(response).to have_gitlab_http_status(412)
expect(response).to render_template :precondition_failed
end
end
end
context 'js' do
subject { get :index, text: "hi \255", format: :js }
it 'renders 412' do
get :index, text: "hi \255", format: :js
if Gitlab.rails5?
expect { subject }.to raise_error(ActionController::BadRequest)
else
subject
json_response = JSON.parse(response.body)
......@@ -704,6 +715,7 @@ describe ApplicationController do
end
end
end
end
context 'X-GitLab-Custom-Error header' do
before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment