Commit d5a1dd74 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Skip highlighting cache for diffs with unsupported characters

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/207124

Sentry error:
https://sentry.gitlab.net/gitlab/gitlabcom/issues/2770092

Changelog: fixed
parent 8131801a
......@@ -132,6 +132,8 @@ module Gitlab
diff_file_id,
gzip_compress(highlighted_diff_lines_hash.to_json)
)
rescue Encoding::UndefinedConversionError
nil
end
# HSETs have to have their expiration date manually updated
......
......@@ -185,6 +185,15 @@ RSpec.describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
expect { cache.send(:write_to_redis_hash, diff_hash) }
.to change { Gitlab::Redis::Cache.with { |r| r.hgetall(cache_key) } }
end
context 'when diff contains unsupported characters' do
let(:diff_hash) { { 'README' => [{ line_code: nil, rich_text: nil, text: [0xff, 0xfe, 0x0, 0x23].pack("c*"), type: "match", index: 0, old_pos: 17, new_pos: 17 }] } }
it 'does not update the cache' do
expect { cache.send(:write_to_redis_hash, diff_hash) }
.not_to change { Gitlab::Redis::Cache.with { |r| r.hgetall(cache_key) } }
end
end
end
describe '#clear' 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