summaryrefslogtreecommitdiff
path: root/lib/gitlab/diff/file.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-30 11:40:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-30 11:40:06 +0000
commit6b3f0a47a2410b5a2a9fc1e78ff2d006b05a3e05 (patch)
treebd4e2f1b1eabdca0f546685e9df8b5a0b649940c /lib/gitlab/diff/file.rb
parent76b84b42f64b8009cc181d5da0c656a8a521986d (diff)
downloadgitlab-ce-6b3f0a47a2410b5a2a9fc1e78ff2d006b05a3e05.tar.gz
Add latest changes from gitlab-org/security/gitlab@14-0-stable-ee
Diffstat (limited to 'lib/gitlab/diff/file.rb')
-rw-r--r--lib/gitlab/diff/file.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index dcd4bbdabf5..35581952f4a 100644
--- a/lib/gitlab/diff/file.rb
+++ b/lib/gitlab/diff/file.rb
@@ -250,7 +250,7 @@ module Gitlab
end
def diffable?
- repository.attributes(file_path).fetch('diff') { true }
+ diffable_by_attribute? && !text_with_binary_notice?
end
def binary_in_repo?
@@ -366,6 +366,15 @@ module Gitlab
private
+ def diffable_by_attribute?
+ repository.attributes(file_path).fetch('diff') { true }
+ end
+
+ # NOTE: Files with unsupported encodings (e.g. UTF-16) are treated as binary by git, but they are recognized as text files during encoding detection. These files have `Binary files a/filename and b/filename differ' as their raw diff content which cannot be used. We need to handle this special case and avoid displaying incorrect diff.
+ def text_with_binary_notice?
+ text? && has_binary_notice?
+ end
+
def fetch_blob(sha, path)
return unless sha