diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-15 17:39:47 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-15 17:39:47 +0000 |
commit | 6aae25209a07a49a2414193ba1500d135c1b497e (patch) | |
tree | f0b42f45dd56936668462ddb23b8d11f4e3ab8f9 /lib | |
parent | 008557581d8a9a428c262e09fe8f36060fe945b9 (diff) | |
download | redmine-6aae25209a07a49a2414193ba1500d135c1b497e.tar.gz redmine-6aae25209a07a49a2414193ba1500d135c1b497e.zip |
Fixed that partial diffs are done against html instead of original code (#9143).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8876 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/unified_diff.rb | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/lib/redmine/unified_diff.rb b/lib/redmine/unified_diff.rb index 3aa348f41..84c376764 100644 --- a/lib/redmine/unified_diff.rb +++ b/lib/redmine/unified_diff.rb @@ -112,11 +112,6 @@ module Redmine private - # Escape the HTML for the diff - def escapeHTML(line) - CGI.escapeHTML(line) - end - def diff_for_added_line if @type == 'sbs' && @removed > 0 && @added < @removed self[-(@removed - @added)] @@ -130,7 +125,7 @@ module Redmine def parse_line(line, type="inline") if line[0, 1] == "+" diff = diff_for_added_line - diff.line_right = escapeHTML line[1..-1] + diff.line_right = line[1..-1] diff.nb_line_right = @line_num_r diff.type_diff_right = 'diff_in' @line_num_r += 1 @@ -138,7 +133,7 @@ module Redmine true elsif line[0, 1] == "-" diff = Diff.new - diff.line_left = escapeHTML line[1..-1] + diff.line_left = line[1..-1] diff.nb_line_left = @line_num_l diff.type_diff_left = 'diff_out' self << diff @@ -149,9 +144,9 @@ module Redmine write_offsets if line[0, 1] =~ /\s/ diff = Diff.new - diff.line_right = escapeHTML line[1..-1] + diff.line_right = line[1..-1] diff.nb_line_right = @line_num_r - diff.line_left = escapeHTML line[1..-1] + diff.line_left = line[1..-1] diff.nb_line_left = @line_num_l self << diff @line_num_l += 1 @@ -224,27 +219,15 @@ module Redmine end def html_line_left - if offsets - line_left.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>') - else - line_left - end + line_to_html(line_left, offsets) end def html_line_right - if offsets - line_right.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>') - else - line_right - end + line_to_html(line_right, offsets) end def html_line - if offsets - line.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>') - else - line - end + line_to_html(line, offsets) end def inspect @@ -254,5 +237,23 @@ module Redmine puts self.nb_line_right puts self.line_right end + + private + + def line_to_html(line, offsets) + if offsets + s = '' + unless offsets.first == 0 + s << CGI.escapeHTML(line[0..offsets.first-1]) + end + s << '<span>' + CGI.escapeHTML(line[offsets.first..offsets.last]) + '</span>' + unless offsets.last == -1 + s << CGI.escapeHTML(line[offsets.last+1..-1]) + end + s + else + CGI.escapeHTML(line) + end + end end end |