##// END OF EJS Templates
Merged r8876 from trunk....
Jean-Philippe Lang -
r8990:90c6a8579bb4
parent child
Show More
@@ -112,11 +112,6 module Redmine
112 112
113 113 private
114 114
115 # Escape the HTML for the diff
116 def escapeHTML(line)
117 CGI.escapeHTML(line)
118 end
119
120 115 def diff_for_added_line
121 116 if @type == 'sbs' && @removed > 0 && @added < @removed
122 117 self[-(@removed - @added)]
@@ -130,7 +125,7 module Redmine
130 125 def parse_line(line, type="inline")
131 126 if line[0, 1] == "+"
132 127 diff = diff_for_added_line
133 diff.line_right = escapeHTML line[1..-1]
128 diff.line_right = line[1..-1]
134 129 diff.nb_line_right = @line_num_r
135 130 diff.type_diff_right = 'diff_in'
136 131 @line_num_r += 1
@@ -138,7 +133,7 module Redmine
138 133 true
139 134 elsif line[0, 1] == "-"
140 135 diff = Diff.new
141 diff.line_left = escapeHTML line[1..-1]
136 diff.line_left = line[1..-1]
142 137 diff.nb_line_left = @line_num_l
143 138 diff.type_diff_left = 'diff_out'
144 139 self << diff
@@ -149,9 +144,9 module Redmine
149 144 write_offsets
150 145 if line[0, 1] =~ /\s/
151 146 diff = Diff.new
152 diff.line_right = escapeHTML line[1..-1]
147 diff.line_right = line[1..-1]
153 148 diff.nb_line_right = @line_num_r
154 diff.line_left = escapeHTML line[1..-1]
149 diff.line_left = line[1..-1]
155 150 diff.nb_line_left = @line_num_l
156 151 self << diff
157 152 @line_num_l += 1
@@ -224,27 +219,15 module Redmine
224 219 end
225 220
226 221 def html_line_left
227 if offsets
228 line_left.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>')
229 else
230 line_left
231 end
222 line_to_html(line_left, offsets)
232 223 end
233 224
234 225 def html_line_right
235 if offsets
236 line_right.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>')
237 else
238 line_right
239 end
226 line_to_html(line_right, offsets)
240 227 end
241 228
242 229 def html_line
243 if offsets
244 line.dup.insert(offsets.first, '<span>').insert(offsets.last, '</span>')
245 else
246 line
247 end
230 line_to_html(line, offsets)
248 231 end
249 232
250 233 def inspect
@@ -254,5 +237,23 module Redmine
254 237 puts self.nb_line_right
255 238 puts self.line_right
256 239 end
240
241 private
242
243 def line_to_html(line, offsets)
244 if offsets
245 s = ''
246 unless offsets.first == 0
247 s << CGI.escapeHTML(line[0..offsets.first-1])
248 end
249 s << '<span>' + CGI.escapeHTML(line[offsets.first..offsets.last]) + '</span>'
250 unless offsets.last == -1
251 s << CGI.escapeHTML(line[offsets.last+1..-1])
252 end
253 s
254 else
255 CGI.escapeHTML(line)
256 end
257 end
257 258 end
258 259 end
@@ -91,6 +91,29 class Redmine::UnifiedDiffTest < ActiveSupport::TestCase
91 91
92 92 end
93 93
94 def test_partials_with_html_entities
95 raw = <<-DIFF
96 --- test.orig.txt Wed Feb 15 16:10:39 2012
97 +++ test.new.txt Wed Feb 15 16:11:25 2012
98 @@ -1,5 +1,5 @@
99 Semicolons were mysteriously appearing in code diffs in the repository
100
101 -void DoSomething(std::auto_ptr<MyClass> myObj)
102 +void DoSomething(const MyClass& myObj)
103
104 DIFF
105
106 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
107 assert_equal 1, diff.size
108 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line_left
109 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[2].html_line_right
110
111 diff = Redmine::UnifiedDiff.new(raw, :type => 'inline')
112 assert_equal 1, diff.size
113 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line
114 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[3].html_line
115 end
116
94 117 def test_line_starting_with_dashes
95 118 diff = Redmine::UnifiedDiff.new(<<-DIFF
96 119 --- old.txt Wed Nov 11 14:24:58 2009
General Comments 0
You need to be logged in to leave comments. Login now