diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-01-22 03:43:06 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-01-22 03:47:17 +0300 |
commit | 150b4f66e6a244b5f6bd1119de3ce68336a9bf9e (patch) | |
tree | 5520435b90d8129c4013ae1d3d5e17a3f4c2d56a /lib/gitlab/diff/highlight.rb | |
parent | 3f7993b5ceb9c5ba616dffef39f9b535482d92c1 (diff) |
Make sure non-highlighted diffs are still escaped
Diffstat (limited to 'lib/gitlab/diff/highlight.rb')
-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..964c89de6c6 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_file + @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 |