summaryrefslogtreecommitdiff
path: root/spec/controllers
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-05-23 22:59:35 -0700
committerStan Hu <stanhu@gmail.com>2016-06-12 07:36:25 -0700
commit0fdfd2dd6e01648f4daf6853f11a3ffc9a678a55 (patch)
tree985c306c1885c68220ba99a40bd5426ac14d52ce /spec/controllers
parentff345f8ba11658c679b423e06bbc42b90af158eb (diff)
downloadgitlab-ce-0fdfd2dd6e01648f4daf6853f11a3ffc9a678a55.tar.gz
Fix Error 500 when viewing a blob with binary characters after the 1024-byte mark
Here was the problem: 1. When determining whether a given blob is viewable text, gitlab_git reads the first 1024 bytes and checks with Linguist whether it is a text or binary file. 2. If the blob is text, GitLab will attempt to display it. 3. However, if the text has binary characters after the first 1024 bytes, then GitLab will attempt to load the entire contents, but the encoding will be ASCII-8BIT since there are binary characters. 4. The Error 500 results when GitLab attempts to display a mix UTF-8 and ASCII-8BIT. To fix this, we load as much data as we are willing to display so that the detection will work properly. Requires an update to gitlab_git: gitlab-org/gitlab_git!86 Closes #13826
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/blob_controller_spec.rb5
-rw-r--r--spec/controllers/projects/commit_controller_spec.rb12
2 files changed, 17 insertions, 0 deletions
diff --git a/spec/controllers/blob_controller_spec.rb b/spec/controllers/blob_controller_spec.rb
index eb91e577b87..465013231f9 100644
--- a/spec/controllers/blob_controller_spec.rb
+++ b/spec/controllers/blob_controller_spec.rb
@@ -38,6 +38,11 @@ describe Projects::BlobController do
let(:id) { 'invalid-branch/README.md' }
it { is_expected.to respond_with(:not_found) }
end
+
+ context "binary file" do
+ let(:id) { 'binary-encoding/encoding/binary-1.bin' }
+ it { is_expected.to respond_with(:success) }
+ end
end
describe 'GET show with tree path' do
diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb
index 438e776ec4b..6e3db10e451 100644
--- a/spec/controllers/projects/commit_controller_spec.rb
+++ b/spec/controllers/projects/commit_controller_spec.rb
@@ -2,6 +2,8 @@ require 'rails_helper'
describe Projects::CommitController do
describe 'GET show' do
+ render_views
+
let(:project) { create(:project) }
before do
@@ -27,6 +29,16 @@ describe Projects::CommitController do
end
end
+ it 'handles binary files' do
+ get(:show,
+ namespace_id: project.namespace.to_param,
+ project_id: project.to_param,
+ id: TestEnv::BRANCH_SHA['binary-encoding'],
+ format: "html")
+
+ expect(response).to be_success
+ end
+
def go(id:)
get :show,
namespace_id: project.namespace.to_param,