diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-11 18:07:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-11 18:07:38 +0300 |
commit | 4eea104c69e59f6fa53c7bc15b986c69f29b60c8 (patch) | |
tree | 2eff1ce7ac4a58de15b1f5980acfdb22c7b92ac0 /spec/lib/gitlab/diff | |
parent | b86f474bf51e20d2db4cf0895d0a8e0894e31c08 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/diff')
-rw-r--r-- | spec/lib/gitlab/diff/highlight_cache_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/line_spec.rb | 44 |
2 files changed, 46 insertions, 7 deletions
diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb index 6dabfd0ef2c..7daf086843b 100644 --- a/spec/lib/gitlab/diff/highlight_cache_spec.rb +++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb @@ -68,6 +68,15 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do expect(diff_file.highlighted_diff_lines.size).to be > 5 end + + it 'assigns highlighted diff lines which rich_text are HTML-safe' do + cache.write_if_empty + cache.decorate(diff_file) + + rich_texts = diff_file.highlighted_diff_lines.map(&:rich_text) + + expect(rich_texts).to all(be_html_safe) + end end describe '#write_if_empty' do diff --git a/spec/lib/gitlab/diff/line_spec.rb b/spec/lib/gitlab/diff/line_spec.rb index 29b9951ba4c..7961bec9d57 100644 --- a/spec/lib/gitlab/diff/line_spec.rb +++ b/spec/lib/gitlab/diff/line_spec.rb @@ -1,18 +1,48 @@ # frozen_string_literal: true +require 'spec_helper' + describe Gitlab::Diff::Line do - describe '.init_from_hash' do + shared_examples 'line object initialized by hash' do it 'round-trips correctly with to_hash' do - line = described_class.new('<input>', 'match', 0, 0, 1, - parent_file: double(:file), - line_code: double(:line_code), - rich_text: '<input>') - - expect(described_class.init_from_hash(line.to_hash).to_hash) + expect(described_class.safe_init_from_hash(line.to_hash).to_hash) .to eq(line.to_hash) end end + let(:line) do + described_class.new('<input>', 'match', 0, 0, 1, + parent_file: double(:file), + line_code: double(:line_code), + rich_text: rich_text) + end + + describe '.init_from_hash' do + let(:rich_text) { '<input>' } + + it_behaves_like 'line object initialized by hash' + end + + describe '.safe_init_from_hash' do + let(:rich_text) { '<input>' } + + it_behaves_like 'line object initialized by hash' + + it 'ensures rich_text is HTML-safe' do + expect(line.rich_text).not_to be_html_safe + + new_line = described_class.safe_init_from_hash(line.to_hash) + + expect(new_line.rich_text).to be_html_safe + end + + context 'when given hash has no rich_text' do + it_behaves_like 'line object initialized by hash' do + let(:rich_text) { nil } + end + end + end + context "when setting rich text" do it 'escapes any HTML special characters in the diff chunk header' do subject = described_class.new("<input>", "", 0, 0, 0) |