summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-01-22 01:43:06 +0100
committerDouwe Maan <douwe@selenight.nl>2016-01-22 01:47:17 +0100
commit150b4f66e6a244b5f6bd1119de3ce68336a9bf9e (patch)
tree5520435b90d8129c4013ae1d3d5e17a3f4c2d56a /lib
parent3f7993b5ceb9c5ba616dffef39f9b535482d92c1 (diff)
downloadgitlab-ce-150b4f66e6a244b5f6bd1119de3ce68336a9bf9e.tar.gz
Make sure non-highlighted diffs are still escapedunescaped-diffs
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/diff/highlight.rb16
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