diff options
author | Robert Speicher <robert@gitlab.com> | 2016-01-22 01:35:39 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-01-22 01:35:39 +0000 |
commit | 9a5f83a30a561a379dd45c5924b9e0dc68ccde41 (patch) | |
tree | 7415eab840a04826586200ede17936ce74a6d25b /lib | |
parent | 3ae74df32d315647a9d3fad1a3e517ccb82e0736 (diff) | |
parent | 82d0fa8e451de384150394d8465f6f165adfeae9 (diff) | |
download | gitlab-ce-9a5f83a30a561a379dd45c5924b9e0dc68ccde41.tar.gz |
Merge branch 'unescaped-diffs' into 'master'
Make sure non-highlighted diffs are still escaped
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/12521
See merge request !2544
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/highlight.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb index 179f8164c84..9283b5e185d 100644 --- a/lib/gitlab/diff/highlight.rb +++ b/lib/gitlab/diff/highlight.rb @@ -1,13 +1,17 @@ module Gitlab module Diff class Highlight - attr_reader :diff_file + attr_reader :diff_file, :diff_lines, :raw_lines delegate :old_path, :new_path, :old_ref, :new_ref, to: :diff_file, prefix: :diff - def initialize(diff_file) - @diff_file = diff_file - @diff_lines = diff_file.diff_lines + def initialize(diff_lines) + if diff_lines.is_a?(Gitlab::Diff::File) + @diff_file = diff_lines + @diff_lines = @diff_file.diff_lines + else + @diff_lines = diff_lines + end @raw_lines = @diff_lines.map(&:text) end @@ -31,7 +35,7 @@ module Gitlab private def highlight_line(diff_line, index) - return html_escape(diff_line.text) unless diff_file.diff_refs + return html_escape(diff_line.text) unless diff_file && diff_file.diff_refs line_prefix = diff_line.text.match(/\A(.)/) ? $1 : ' ' @@ -52,10 +56,12 @@ module Gitlab end def old_lines + return unless diff_file @old_lines ||= Gitlab::Highlight.highlight_lines(*processing_args(:old)) end def new_lines + return unless diff_file @new_lines ||= Gitlab::Highlight.highlight_lines(*processing_args(:new)) end |