##// END OF EJS Templates
fix diff error in case of line_left out of range (#13644)...
Toshi MARUYAMA -
r11477:6469e9a5a338
parent child
Show More
@@ -0,0 +1,7
1 --- a.txt 2013-04-05 14:19:39.000000000 +0900
2 +++ b.txt 2013-04-05 14:19:51.000000000 +0900
3 @@ -1,3 +1,3 @@
4 aaaa
5 -日本
6 +日本語
7 bbbb
@@ -0,0 +1,7
1 --- a.txt 2013-04-05 14:19:39.000000000 +0900
2 +++ b.txt 2013-04-05 14:19:51.000000000 +0900
3 @@ -1,3 +1,3 @@
4 aaaa
5 -日本
6 +にっぽん日本
7 bbbb
@@ -199,7 +199,7 module Redmine
199 while starting < max && line_left[starting] == line_right[starting]
199 while starting < max && line_left[starting] == line_right[starting]
200 starting += 1
200 starting += 1
201 end
201 end
202 unless "".respond_to?(:force_encoding)
202 if (! "".respond_to?(:force_encoding)) && starting < line_left.size
203 while line_left[starting].ord.between?(128, 191) && starting > 0
203 while line_left[starting].ord.between?(128, 191) && starting > 0
204 starting -= 1
204 starting -= 1
205 end
205 end
@@ -208,7 +208,7 module Redmine
208 while ending >= -(max - starting) && line_left[ending] == line_right[ending]
208 while ending >= -(max - starting) && line_left[ending] == line_right[ending]
209 ending -= 1
209 ending -= 1
210 end
210 end
211 unless "".respond_to?(:force_encoding)
211 if (! "".respond_to?(:force_encoding)) && ending > (-1 * line_left.size)
212 while line_left[ending].ord.between?(128, 191) && ending > -1
212 while line_left[ending].ord.between?(128, 191) && ending > -1
213 ending -= 1
213 ending -= 1
214 end
214 end
@@ -244,6 +244,70 DIFF
244 end
244 end
245 end
245 end
246
246
247 def test_offset_range_ascii_1
248 raw = <<-DIFF
249 --- a.txt 2013-04-05 14:19:39.000000000 +0900
250 +++ b.txt 2013-04-05 14:19:51.000000000 +0900
251 @@ -1,3 +1,3 @@
252 aaaa
253 -abc
254 +abcd
255 bbbb
256 DIFF
257 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
258 assert_equal 1, diff.size
259 assert_equal 3, diff.first.size
260 assert_equal "abc<span></span>", diff.first[1].html_line_left
261 assert_equal "abc<span>d</span>", diff.first[1].html_line_right
262 end
263
264 def test_offset_range_ascii_2
265 raw = <<-DIFF
266 --- a.txt 2013-04-05 14:19:39.000000000 +0900
267 +++ b.txt 2013-04-05 14:19:51.000000000 +0900
268 @@ -1,3 +1,3 @@
269 aaaa
270 -abc
271 +zabc
272 bbbb
273 DIFF
274 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
275 assert_equal 1, diff.size
276 assert_equal 3, diff.first.size
277 assert_equal "<span></span>abc", diff.first[1].html_line_left
278 assert_equal "<span>z</span>abc", diff.first[1].html_line_right
279 end
280
281 def test_offset_range_japanese_1
282 ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span></span>"
283 ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
284 ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x9e</span>"
285 ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
286 with_settings :repositories_encodings => '' do
287 diff = Redmine::UnifiedDiff.new(
288 read_diff_fixture('issue-13644-1.diff'), :type => 'sbs')
289 assert_equal 1, diff.size
290 assert_equal 3, diff.first.size
291 assert_equal ja1, diff.first[1].html_line_left
292 assert_equal ja2, diff.first[1].html_line_right
293 end
294 end
295
296 def test_offset_range_japanese_2
297 ja1 = "<span></span>\xe6\x97\xa5\xe6\x9c\xac"
298 ja1.force_encoding('UTF-8') if ja1.respond_to?(:force_encoding)
299 ja2 = "<span>\xe3\x81\xab\xe3\x81\xa3\xe3\x81\xbd\xe3\x82\x93</span>\xe6\x97\xa5\xe6\x9c\xac"
300 ja2.force_encoding('UTF-8') if ja2.respond_to?(:force_encoding)
301 with_settings :repositories_encodings => '' do
302 diff = Redmine::UnifiedDiff.new(
303 read_diff_fixture('issue-13644-2.diff'), :type => 'sbs')
304 assert_equal 1, diff.size
305 assert_equal 3, diff.first.size
306 assert_equal ja1, diff.first[1].html_line_left
307 assert_equal ja2, diff.first[1].html_line_right
308 end
309 end
310
247 private
311 private
248
312
249 def read_diff_fixture(filename)
313 def read_diff_fixture(filename)
General Comments 0
You need to be logged in to leave comments. Login now