Commit 59af98f1 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rails5-fix-utf' into 'master'

Use InvalidUTF8ErrorHandler only for rails 4

Closes #51908

See merge request gitlab-org/gitlab-ce!22340
parents 6ea674d1 c6a4c923
...@@ -12,7 +12,9 @@ class ApplicationController < ActionController::Base ...@@ -12,7 +12,9 @@ class ApplicationController < ActionController::Base
include WorkhorseHelper include WorkhorseHelper
include EnforcesTwoFactorAuthentication include EnforcesTwoFactorAuthentication
include WithPerformanceBar 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_sessionless_user!
before_action :authenticate_user! before_action :authenticate_user!
......
...@@ -685,22 +685,34 @@ describe ApplicationController do ...@@ -685,22 +685,34 @@ describe ApplicationController do
end end
context 'html' do context 'html' do
subject { get :index, text: "hi \255" }
it 'renders 412' do 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 have_gitlab_http_status(412)
expect(response).to render_template :precondition_failed expect(response).to render_template :precondition_failed
end
end end
end end
context 'js' do context 'js' do
subject { get :index, text: "hi \255", format: :js }
it 'renders 412' do 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) json_response = JSON.parse(response.body)
expect(response).to have_gitlab_http_status(412) expect(response).to have_gitlab_http_status(412)
expect(json_response['error']).to eq('Invalid UTF-8') expect(json_response['error']).to eq('Invalid UTF-8')
end
end end
end end
end end
......
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