diff options
author | Chantal Rollison <crollison@gitlab.com> | 2018-08-11 13:33:15 -0700 |
---|---|---|
committer | Chantal Rollison <crollison@gitlab.com> | 2018-08-21 07:37:33 -0700 |
commit | 81a403f05f05f4ee8d65db6185cbd0856f7c5189 (patch) | |
tree | a16142b2fa175d6d16b70e8cd86ba3f681947b18 /spec/lib/gitlab/diff | |
parent | 3cd61fea03b360af50793488a83e8147a1cf3311 (diff) | |
download | gitlab-ce-81a403f05f05f4ee8d65db6185cbd0856f7c5189.tar.gz |
Escaped html characters
Diffstat (limited to 'spec/lib/gitlab/diff')
-rw-r--r-- | spec/lib/gitlab/diff/highlight_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/line_spec.rb | 10 |
2 files changed, 15 insertions, 5 deletions
diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb index 7c9e8c8d04e..3c8cf9c56cc 100644 --- a/spec/lib/gitlab/diff/highlight_spec.rb +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -24,19 +24,19 @@ describe Gitlab::Diff::Highlight do it 'highlights and marks unchanged lines' do code = %Q{ <span id="LC7" class="line" lang="ruby"> <span class="k">def</span> <span class="nf">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span></span>\n} - expect(subject[2].text).to eq(code) + expect(subject[2].rich_text).to eq(code) end it 'highlights and marks removed lines' do code = %Q{-<span id="LC9" class="line" lang="ruby"> <span class="k">raise</span> <span class="s2">"System commands must be given as an array of strings"</span></span>\n} - expect(subject[4].text).to eq(code) + expect(subject[4].rich_text).to eq(code) end it 'highlights and marks added lines' do code = %Q{+<span id="LC9" class="line" lang="ruby"> <span class="k">raise</span> <span class="no"><span class="idiff left">RuntimeError</span></span><span class="p"><span class="idiff">,</span></span><span class="idiff right"> </span><span class="s2">"System commands must be given as an array of strings"</span></span>\n} - expect(subject[5].text).to eq(code) + expect(subject[5].rich_text).to eq(code) end end @@ -69,8 +69,8 @@ describe Gitlab::Diff::Highlight do it 'marks added lines' do code = %q{+ raise <span class="idiff left right">RuntimeError, </span>"System commands must be given as an array of strings"} - expect(subject[5].text).to eq(code) - expect(subject[5].text).to be_html_safe + expect(subject[5].rich_text).to eq(code) + expect(subject[5].rich_text).to be_html_safe end context 'when the inline diff marker has an invalid range' do diff --git a/spec/lib/gitlab/diff/line_spec.rb b/spec/lib/gitlab/diff/line_spec.rb new file mode 100644 index 00000000000..e9d382d59c6 --- /dev/null +++ b/spec/lib/gitlab/diff/line_spec.rb @@ -0,0 +1,10 @@ +describe Gitlab::Diff::Line do + 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) + line = subject.as_json + + expect(line[:rich_text]).to eq("<input>") + end + end +end |