##// END OF EJS Templates
Merged r11706 and r11707 from trunk to 2.3-stable (#13644)...
Toshi MARUYAMA -
r11479:655c50849d56
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
@@ -1,290 +1,294
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module Redmine
19 19 # Class used to parse unified diffs
20 20 class UnifiedDiff < Array
21 21 attr_reader :diff_type, :diff_style
22 22
23 23 def initialize(diff, options={})
24 24 options.assert_valid_keys(:type, :style, :max_lines)
25 25 diff = diff.split("\n") if diff.is_a?(String)
26 26 @diff_type = options[:type] || 'inline'
27 27 @diff_style = options[:style]
28 28 lines = 0
29 29 @truncated = false
30 30 diff_table = DiffTable.new(diff_type, diff_style)
31 31 diff.each do |line_raw|
32 32 line = Redmine::CodesetUtil.to_utf8_by_setting(line_raw)
33 33 unless diff_table.add_line(line)
34 34 self << diff_table if diff_table.length > 0
35 35 diff_table = DiffTable.new(diff_type, diff_style)
36 36 end
37 37 lines += 1
38 38 if options[:max_lines] && lines > options[:max_lines]
39 39 @truncated = true
40 40 break
41 41 end
42 42 end
43 43 self << diff_table unless diff_table.empty?
44 44 self
45 45 end
46 46
47 47 def truncated?; @truncated; end
48 48 end
49 49
50 50 # Class that represents a file diff
51 51 class DiffTable < Array
52 52 attr_reader :file_name
53 53
54 54 # Initialize with a Diff file and the type of Diff View
55 55 # The type view must be inline or sbs (side_by_side)
56 56 def initialize(type="inline", style=nil)
57 57 @parsing = false
58 58 @added = 0
59 59 @removed = 0
60 60 @type = type
61 61 @style = style
62 62 @file_name = nil
63 63 @git_diff = false
64 64 end
65 65
66 66 # Function for add a line of this Diff
67 67 # Returns false when the diff ends
68 68 def add_line(line)
69 69 unless @parsing
70 70 if line =~ /^(---|\+\+\+) (.*)$/
71 71 self.file_name = $2
72 72 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
73 73 @line_num_l = $2.to_i
74 74 @line_num_r = $5.to_i
75 75 @parsing = true
76 76 end
77 77 else
78 78 if line =~ %r{^[^\+\-\s@\\]}
79 79 @parsing = false
80 80 return false
81 81 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
82 82 @line_num_l = $2.to_i
83 83 @line_num_r = $5.to_i
84 84 else
85 85 parse_line(line, @type)
86 86 end
87 87 end
88 88 return true
89 89 end
90 90
91 91 def each_line
92 92 prev_line_left, prev_line_right = nil, nil
93 93 each do |line|
94 94 spacing = prev_line_left && prev_line_right && (line.nb_line_left != prev_line_left+1) && (line.nb_line_right != prev_line_right+1)
95 95 yield spacing, line
96 96 prev_line_left = line.nb_line_left.to_i if line.nb_line_left.to_i > 0
97 97 prev_line_right = line.nb_line_right.to_i if line.nb_line_right.to_i > 0
98 98 end
99 99 end
100 100
101 101 def inspect
102 102 puts '### DIFF TABLE ###'
103 103 puts "file : #{file_name}"
104 104 self.each do |d|
105 105 d.inspect
106 106 end
107 107 end
108 108
109 109 private
110 110
111 111 def file_name=(arg)
112 112 both_git_diff = false
113 113 if file_name.nil?
114 114 @git_diff = true if arg =~ %r{^(a/|/dev/null)}
115 115 else
116 116 both_git_diff = (@git_diff && arg =~ %r{^(b/|/dev/null)})
117 117 end
118 118 if both_git_diff
119 119 if file_name && arg == "/dev/null"
120 120 # keep the original file name
121 121 @file_name = file_name.sub(%r{^a/}, '')
122 122 else
123 123 # remove leading b/
124 124 @file_name = arg.sub(%r{^b/}, '')
125 125 end
126 126 elsif @style == "Subversion"
127 127 # removing trailing "(revision nn)"
128 128 @file_name = arg.sub(%r{\t+\(.*\)$}, '')
129 129 else
130 130 @file_name = arg
131 131 end
132 132 end
133 133
134 134 def diff_for_added_line
135 135 if @type == 'sbs' && @removed > 0 && @added < @removed
136 136 self[-(@removed - @added)]
137 137 else
138 138 diff = Diff.new
139 139 self << diff
140 140 diff
141 141 end
142 142 end
143 143
144 144 def parse_line(line, type="inline")
145 145 if line[0, 1] == "+"
146 146 diff = diff_for_added_line
147 147 diff.line_right = line[1..-1]
148 148 diff.nb_line_right = @line_num_r
149 149 diff.type_diff_right = 'diff_in'
150 150 @line_num_r += 1
151 151 @added += 1
152 152 true
153 153 elsif line[0, 1] == "-"
154 154 diff = Diff.new
155 155 diff.line_left = line[1..-1]
156 156 diff.nb_line_left = @line_num_l
157 157 diff.type_diff_left = 'diff_out'
158 158 self << diff
159 159 @line_num_l += 1
160 160 @removed += 1
161 161 true
162 162 else
163 163 write_offsets
164 164 if line[0, 1] =~ /\s/
165 165 diff = Diff.new
166 166 diff.line_right = line[1..-1]
167 167 diff.nb_line_right = @line_num_r
168 168 diff.line_left = line[1..-1]
169 169 diff.nb_line_left = @line_num_l
170 170 self << diff
171 171 @line_num_l += 1
172 172 @line_num_r += 1
173 173 true
174 174 elsif line[0, 1] = "\\"
175 175 true
176 176 else
177 177 false
178 178 end
179 179 end
180 180 end
181 181
182 182 def write_offsets
183 183 if @added > 0 && @added == @removed
184 184 @added.times do |i|
185 185 line = self[-(1 + i)]
186 186 removed = (@type == 'sbs') ? line : self[-(1 + @added + i)]
187 187 offsets = offsets(removed.line_left, line.line_right)
188 188 removed.offsets = line.offsets = offsets
189 189 end
190 190 end
191 191 @added = 0
192 192 @removed = 0
193 193 end
194 194
195 195 def offsets(line_left, line_right)
196 196 if line_left.present? && line_right.present? && line_left != line_right
197 197 max = [line_left.size, line_right.size].min
198 198 starting = 0
199 199 while starting < max && line_left[starting] == line_right[starting]
200 200 starting += 1
201 201 end
202 if (! "".respond_to?(:force_encoding)) && starting < line_left.size
202 203 while line_left[starting].ord.between?(128, 191) && starting > 0
203 204 starting -= 1
204 205 end
206 end
205 207 ending = -1
206 208 while ending >= -(max - starting) && line_left[ending] == line_right[ending]
207 209 ending -= 1
208 210 end
211 if (! "".respond_to?(:force_encoding)) && ending > (-1 * line_left.size)
209 212 while line_left[ending].ord.between?(128, 191) && ending > -1
210 213 ending -= 1
211 214 end
215 end
212 216 unless starting == 0 && ending == -1
213 217 [starting, ending]
214 218 end
215 219 end
216 220 end
217 221 end
218 222
219 223 # A line of diff
220 224 class Diff
221 225 attr_accessor :nb_line_left
222 226 attr_accessor :line_left
223 227 attr_accessor :nb_line_right
224 228 attr_accessor :line_right
225 229 attr_accessor :type_diff_right
226 230 attr_accessor :type_diff_left
227 231 attr_accessor :offsets
228 232
229 233 def initialize()
230 234 self.nb_line_left = ''
231 235 self.nb_line_right = ''
232 236 self.line_left = ''
233 237 self.line_right = ''
234 238 self.type_diff_right = ''
235 239 self.type_diff_left = ''
236 240 end
237 241
238 242 def type_diff
239 243 type_diff_right == 'diff_in' ? type_diff_right : type_diff_left
240 244 end
241 245
242 246 def line
243 247 type_diff_right == 'diff_in' ? line_right : line_left
244 248 end
245 249
246 250 def html_line_left
247 251 line_to_html(line_left, offsets)
248 252 end
249 253
250 254 def html_line_right
251 255 line_to_html(line_right, offsets)
252 256 end
253 257
254 258 def html_line
255 259 line_to_html(line, offsets)
256 260 end
257 261
258 262 def inspect
259 263 puts '### Start Line Diff ###'
260 264 puts self.nb_line_left
261 265 puts self.line_left
262 266 puts self.nb_line_right
263 267 puts self.line_right
264 268 end
265 269
266 270 private
267 271
268 272 def line_to_html(line, offsets)
269 273 html = line_to_html_raw(line, offsets)
270 274 html.force_encoding('UTF-8') if html.respond_to?(:force_encoding)
271 275 html
272 276 end
273 277
274 278 def line_to_html_raw(line, offsets)
275 279 if offsets
276 280 s = ''
277 281 unless offsets.first == 0
278 282 s << CGI.escapeHTML(line[0..offsets.first-1])
279 283 end
280 284 s << '<span>' + CGI.escapeHTML(line[offsets.first..offsets.last]) + '</span>'
281 285 unless offsets.last == -1
282 286 s << CGI.escapeHTML(line[offsets.last+1..-1])
283 287 end
284 288 s
285 289 else
286 290 CGI.escapeHTML(line)
287 291 end
288 292 end
289 293 end
290 294 end
@@ -1,252 +1,316
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../../../test_helper', __FILE__)
19 19
20 20 class Redmine::UnifiedDiffTest < ActiveSupport::TestCase
21 21 def test_subversion_diff
22 22 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'))
23 23 # number of files
24 24 assert_equal 4, diff.size
25 25 assert diff.detect {|file| file.file_name =~ %r{^config/settings.yml}}
26 26 end
27 27
28 28 def test_truncate_diff
29 29 diff = Redmine::UnifiedDiff.new(read_diff_fixture('subversion.diff'), :max_lines => 20)
30 30 assert_equal 2, diff.size
31 31 end
32 32
33 33 def test_inline_partials
34 34 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'))
35 35 assert_equal 1, diff.size
36 36 diff = diff.first
37 37 assert_equal 43, diff.size
38 38
39 39 assert_equal [51, -1], diff[0].offsets
40 40 assert_equal [51, -1], diff[1].offsets
41 41 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line
42 42 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[1].html_line
43 43
44 44 assert_nil diff[2].offsets
45 45 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line
46 46
47 47 assert_equal [0, -14], diff[3].offsets
48 48 assert_equal [0, -14], diff[4].offsets
49 49 assert_equal '<span>Ut sed</span> auctor justo', diff[3].html_line
50 50 assert_equal '<span>xxx</span> auctor justo', diff[4].html_line
51 51
52 52 assert_equal [13, -19], diff[6].offsets
53 53 assert_equal [13, -19], diff[7].offsets
54 54
55 55 assert_equal [24, -8], diff[9].offsets
56 56 assert_equal [24, -8], diff[10].offsets
57 57
58 58 assert_equal [37, -1], diff[12].offsets
59 59 assert_equal [37, -1], diff[13].offsets
60 60
61 61 assert_equal [0, -38], diff[15].offsets
62 62 assert_equal [0, -38], diff[16].offsets
63 63 end
64 64
65 65 def test_side_by_side_partials
66 66 diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs')
67 67 assert_equal 1, diff.size
68 68 diff = diff.first
69 69 assert_equal 32, diff.size
70 70
71 71 assert_equal [51, -1], diff[0].offsets
72 72 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line_left
73 73 assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[0].html_line_right
74 74
75 75 assert_nil diff[1].offsets
76 76 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_left
77 77 assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_right
78 78
79 79 assert_equal [0, -14], diff[2].offsets
80 80 assert_equal '<span>Ut sed</span> auctor justo', diff[2].html_line_left
81 81 assert_equal '<span>xxx</span> auctor justo', diff[2].html_line_right
82 82
83 83 assert_equal [13, -19], diff[4].offsets
84 84 assert_equal [24, -8], diff[6].offsets
85 85 assert_equal [37, -1], diff[8].offsets
86 86 assert_equal [0, -38], diff[10].offsets
87 87
88 88 end
89 89
90 90 def test_partials_with_html_entities
91 91 raw = <<-DIFF
92 92 --- test.orig.txt Wed Feb 15 16:10:39 2012
93 93 +++ test.new.txt Wed Feb 15 16:11:25 2012
94 94 @@ -1,5 +1,5 @@
95 95 Semicolons were mysteriously appearing in code diffs in the repository
96 96
97 97 -void DoSomething(std::auto_ptr<MyClass> myObj)
98 98 +void DoSomething(const MyClass& myObj)
99 99
100 100 DIFF
101 101
102 102 diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
103 103 assert_equal 1, diff.size
104 104 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line_left
105 105 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[2].html_line_right
106 106
107 107 diff = Redmine::UnifiedDiff.new(raw, :type => 'inline')
108 108 assert_equal 1, diff.size
109 109 assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line
110 110 assert_equal 'void DoSomething(<span>const MyClass&amp;</span> myObj)', diff.first[3].html_line
111 111 end
112 112
113 113 def test_line_starting_with_dashes
114 114 diff = Redmine::UnifiedDiff.new(<<-DIFF
115 115 --- old.txt Wed Nov 11 14:24:58 2009
116 116 +++ new.txt Wed Nov 11 14:25:02 2009
117 117 @@ -1,8 +1,4 @@
118 118 -Lines that starts with dashes:
119 119 -
120 120 -------------------------
121 121 --- file.c
122 122 -------------------------
123 123 +A line that starts with dashes:
124 124
125 125 and removed.
126 126
127 127 @@ -23,4 +19,4 @@
128 128
129 129
130 130
131 131 -Another chunk of change
132 132 +Another chunk of changes
133 133
134 134 DIFF
135 135 )
136 136 assert_equal 1, diff.size
137 137 end
138 138
139 139 def test_one_line_new_files
140 140 diff = Redmine::UnifiedDiff.new(<<-DIFF
141 141 diff -r 000000000000 -r ea98b14f75f0 README1
142 142 --- /dev/null
143 143 +++ b/README1
144 144 @@ -0,0 +1,1 @@
145 145 +test1
146 146 diff -r 000000000000 -r ea98b14f75f0 README2
147 147 --- /dev/null
148 148 +++ b/README2
149 149 @@ -0,0 +1,1 @@
150 150 +test2
151 151 diff -r 000000000000 -r ea98b14f75f0 README3
152 152 --- /dev/null
153 153 +++ b/README3
154 154 @@ -0,0 +1,3 @@
155 155 +test4
156 156 +test5
157 157 +test6
158 158 diff -r 000000000000 -r ea98b14f75f0 README4
159 159 --- /dev/null
160 160 +++ b/README4
161 161 @@ -0,0 +1,3 @@
162 162 +test4
163 163 +test5
164 164 +test6
165 165 DIFF
166 166 )
167 167 assert_equal 4, diff.size
168 168 assert_equal "README1", diff[0].file_name
169 169 end
170 170
171 171 def test_both_git_diff
172 172 diff = Redmine::UnifiedDiff.new(<<-DIFF
173 173 # HG changeset patch
174 174 # User test
175 175 # Date 1348014182 -32400
176 176 # Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f
177 177 # Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e
178 178 modify test1.txt
179 179
180 180 diff -r 180b6605936c -r d1c871b8ef11 test1.txt
181 181 --- a/test1.txt
182 182 +++ b/test1.txt
183 183 @@ -1,1 +1,1 @@
184 184 -test1
185 185 +modify test1
186 186 DIFF
187 187 )
188 188 assert_equal 1, diff.size
189 189 assert_equal "test1.txt", diff[0].file_name
190 190 end
191 191
192 192 def test_include_a_b_slash
193 193 diff = Redmine::UnifiedDiff.new(<<-DIFF
194 194 --- test1.txt
195 195 +++ b/test02.txt
196 196 @@ -1 +0,0 @@
197 197 -modify test1
198 198 DIFF
199 199 )
200 200 assert_equal 1, diff.size
201 201 assert_equal "b/test02.txt", diff[0].file_name
202 202
203 203 diff = Redmine::UnifiedDiff.new(<<-DIFF
204 204 --- a/test1.txt
205 205 +++ a/test02.txt
206 206 @@ -1 +0,0 @@
207 207 -modify test1
208 208 DIFF
209 209 )
210 210 assert_equal 1, diff.size
211 211 assert_equal "a/test02.txt", diff[0].file_name
212 212
213 213 diff = Redmine::UnifiedDiff.new(<<-DIFF
214 214 --- a/test1.txt
215 215 +++ test02.txt
216 216 @@ -1 +0,0 @@
217 217 -modify test1
218 218 DIFF
219 219 )
220 220 assert_equal 1, diff.size
221 221 assert_equal "test02.txt", diff[0].file_name
222 222 end
223 223
224 224 def test_utf8_ja
225 225 ja = " text_tip_issue_end_day: "
226 226 ja += "\xe3\x81\x93\xe3\x81\xae\xe6\x97\xa5\xe3\x81\xab\xe7\xb5\x82\xe4\xba\x86\xe3\x81\x99\xe3\x82\x8b<span>\xe3\x82\xbf\xe3\x82\xb9\xe3\x82\xaf</span>"
227 227 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
228 228 with_settings :repositories_encodings => '' do
229 229 diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ja.diff'), :type => 'inline')
230 230 assert_equal 1, diff.size
231 231 assert_equal 12, diff.first.size
232 232 assert_equal ja, diff.first[4].html_line_left
233 233 end
234 234 end
235 235
236 236 def test_utf8_ru
237 237 ru = " other: &quot;\xd0\xbe\xd0\xba\xd0\xbe\xd0\xbb\xd0\xbe %{count} \xd1\x87\xd0\xb0\xd1\x81<span>\xd0\xb0</span>&quot;"
238 238 ru.force_encoding('UTF-8') if ru.respond_to?(:force_encoding)
239 239 with_settings :repositories_encodings => '' do
240 240 diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ru.diff'), :type => 'inline')
241 241 assert_equal 1, diff.size
242 242 assert_equal 8, diff.first.size
243 243 assert_equal ru, diff.first[3].html_line_left
244 244 end
245 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 311 private
248 312
249 313 def read_diff_fixture(filename)
250 314 File.new(File.join(File.dirname(__FILE__), '/../../../fixtures/diffs', filename)).read
251 315 end
252 316 end
General Comments 0
You need to be logged in to leave comments. Login now