diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-08-15 07:09:05 +0200 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-08-17 19:55:07 +0200 |
commit | c271fdc80fd17e1931a1d912e231bec2b8e3d098 (patch) | |
tree | 1e5372e9cb8bfc5a1429e3e96e127c4168c1c59a /lib | |
parent | 04f7f394d3825e3290f523dce28d42b7c87fc9bb (diff) | |
download | gitlab-ce-36041-notification-title.tar.gz |
Don't escape html entities when rich == raw line36041-notification-title
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/string_range_marker.rb | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/gitlab/string_range_marker.rb b/lib/gitlab/string_range_marker.rb index 94fba0a221a..11aeec1ebfa 100644 --- a/lib/gitlab/string_range_marker.rb +++ b/lib/gitlab/string_range_marker.rb @@ -1,21 +1,31 @@ module Gitlab class StringRangeMarker - attr_accessor :raw_line, :rich_line - - def initialize(raw_line, rich_line = raw_line) - @raw_line = raw_line - @rich_line = ERB::Util.html_escape(rich_line) + attr_accessor :raw_line, :rich_line, :html_escaped + + def initialize(raw_line, rich_line = nil) + @raw_line = raw_line.dup + if rich_line.nil? + @rich_line = raw_line.dup + @html_escaped = false + else + @rich_line = ERB::Util.html_escape(rich_line) + @html_escaped = true + end end def mark(marker_ranges) return rich_line unless marker_ranges - rich_marker_ranges = [] - marker_ranges.each do |range| - # Map the inline-diff range based on the raw line to character positions in the rich line - rich_positions = position_mapping[range].flatten - # Turn the array of character positions into ranges - rich_marker_ranges.concat(collapse_ranges(rich_positions)) + if html_escaped + rich_marker_ranges = [] + marker_ranges.each do |range| + # Map the inline-diff range based on the raw line to character positions in the rich line + rich_positions = position_mapping[range].flatten + # Turn the array of character positions into ranges + rich_marker_ranges.concat(collapse_ranges(rich_positions)) + end + else + rich_marker_ranges = marker_ranges end offset = 0 @@ -31,7 +41,7 @@ module Gitlab offset += text.length - original_text.length end - rich_line.html_safe + @html_escaped ? rich_line.html_safe : rich_line end private |