diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-01-20 18:44:27 +0100 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-01-20 18:44:27 +0100 |
commit | 577f2fb47a7ef57415b78b49d5c746d4e99f6a98 (patch) | |
tree | ef621d0febcae9079253b93ae5c319ae94e8d4de /lib/gitlab/diff/highlight.rb | |
parent | 26f7d023e6d15f4deab39f74509bd6dddebf6974 (diff) | |
download | gitlab-ce-577f2fb47a7ef57415b78b49d5c746d4e99f6a98.tar.gz |
Save and use actual diff base commit for MR diff highlighting
Diffstat (limited to 'lib/gitlab/diff/highlight.rb')
-rw-r--r-- | lib/gitlab/diff/highlight.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb index b6875f07279..fe084a7399a 100644 --- a/lib/gitlab/diff/highlight.rb +++ b/lib/gitlab/diff/highlight.rb @@ -31,6 +31,8 @@ module Gitlab private def highlight_line(diff_line, index) + return html_escape(diff_line.text) unless diff_file.diff_refs + line_prefix = diff_line.text.match(/\A([+-])/) ? $1 : ' ' case diff_line.type @@ -42,7 +44,7 @@ module Gitlab # Only update text if line is found. This will prevent # issues with submodules given the line only exists in diff content. - rich_line ? line_prefix + rich_line : diff_line.text + rich_line ? line_prefix + rich_line : html_escape(diff_line.text) end def inline_diffs @@ -63,6 +65,11 @@ module Gitlab [ref.project.repository, ref.id, path] end + + def html_escape(str) + replacements = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' } + str.gsub(/[&"'><]/, replacements) + end end end end |