Merge request diff images don't display due to being marked as text instead of binary
In gitlab-com/www-gitlab-com!89335 (diffs), the new images aren't being displayed automatically:
[ gprd ] production> img = mr.merge_request_diff.diffs.diff_files.to_a.last
=> #<Gitlab::Diff::File:0x00007f473e04bbb8 @diff=#<Gitlab::Git::Diff:0x00007f473fa6aaa8 @expanded=false, @diff="Binary files /dev/null and b/source/images/blogimages/postgresql-subtransactio...
[ gprd ] production> img.new_blob.binary_in_repo?
=> false
The blob's binary
state is set in https://gitlab.com/gitlab-org/gitlab/blob/91f0a0771e1562f87cb6b198c02818b0b0fb0f24/lib/gitlab/git/blob.rb#L76, which calls EncodingHelper.detect_libgit2_binary?
:
[ gprd ] production> include Gitlab::EncodingHelper
=> Object
[ gprd ] production> detect_libgit2_binary?(img.new_blob.data)
=> true
These PNG files are clearly binary files, but I wonder if somehow the cache_key
is being set somewhere causing the cached_encoding_detection
feature flag to erroneously store a cache value: https://gitlab.com/gitlab-org/gitlab/blob/e804c0090501fb4c92e067f16f962018efef1f26/lib/gitlab/encoding_helper.rb#L46.
/cc: @robotmay_gitlab
Edited by Stan Hu