Project

General

Profile

Patch #31004 » 31004-hexadecimal-encoded-to-frozen-string.patch

Yuichi HARADA, 2019-03-19 03:35

View differences:

test/functional/attachments_controller_test.rb
143 143
    assert a.save
144 144
    assert_equal 'japanese-utf-8.txt', a.filename
145 145

  
146
    str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
147

  
148 146
    get :show, :params => {
149 147
        :id => a.id
150 148
      }
......
152 150
    assert_equal 'text/html', @response.content_type
153 151
    assert_select 'tr#L1' do
154 152
      assert_select 'th.line-num', :text => '1'
155
      assert_select 'td', :text => /#{str_japanese}/
153
      assert_select 'td', :text => /日本語/
156 154
    end
157 155
  end
158 156

  
......
501 499
          '1' => {
502 500
            :filename => 'newname.text',
503 501
            :description => ''
504
          },    
502
          },
505 503
                  '4' => {
506 504
            :filename => 'newname.rb',
507 505
            :description => 'Renamed'
508
          },    
509
                
506
          },
507

  
510 508
        }
511 509
      }
512 510

  
......
525 523
          '1' => {
526 524
            :filename => '',
527 525
            :description => ''
528
          },    
526
          },
529 527
                  '4' => {
530 528
            :filename => 'newname.rb',
531 529
            :description => 'Renamed'
532
          },    
533
                
530
          },
531

  
534 532
        }
535 533
      }
536 534

  
test/functional/issues_controller_test.rb
772 772

  
773 773
  def test_index_csv_big_5
774 774
    with_settings :default_language => "zh-TW" do
775
      str_utf8  = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
776
      str_big5  = "\xa4@\xa4\xeb".force_encoding('Big5')
775
      str_utf8  = '一月'
776
      str_big5  = (+"\xa4@\xa4\xeb").force_encoding('Big5')
777 777
      issue = Issue.generate!(:subject => str_utf8)
778 778

  
779 779
      get :index, :params => {
......
784 784
      assert_equal 'text/csv; header=present', @response.content_type
785 785
      lines = @response.body.chomp.split("\n")
786 786
      header = lines[0]
787
      status = "\xaa\xac\xbaA".force_encoding('Big5')
787
      status = (+"\xaa\xac\xbaA").force_encoding('Big5')
788 788
      assert_include status, header
789 789
      issue_line = lines.find {|l| l =~ /^#{issue.id},/}
790 790
      assert_include str_big5, issue_line
......
793 793

  
794 794
  def test_index_csv_cannot_convert_should_be_replaced_big_5
795 795
    with_settings :default_language => "zh-TW" do
796
      str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
796
      str_utf8  = '以内'
797 797
      issue = Issue.generate!(:subject => str_utf8)
798 798

  
799 799
      get :index, :params => {
......
807 807
      lines = @response.body.chomp.split("\n")
808 808
      header = lines[0]
809 809
      issue_line = lines.find {|l| l =~ /^#{issue.id},/}
810
      s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status
810
      s1 = (+"\xaa\xac\xbaA").force_encoding('Big5') # status
811 811
      assert header.include?(s1)
812 812
      s2 = issue_line.split(",")[2]
813
      s3 = "\xa5H?".force_encoding('Big5') # subject
813
      s3 = (+"\xa5H?").force_encoding('Big5') # subject
814 814
      assert_equal s3, s2
815 815
    end
816 816
  end
......
2345 2345
  end
2346 2346

  
2347 2347
  def test_export_to_pdf_with_utf8_u_fffd
2348
    # U+FFFD
2349
    s = "\xef\xbf\xbd"
2350
    s.force_encoding('UTF-8') if s.respond_to?(:force_encoding)
2351
    issue = Issue.generate!(:subject => s)
2348
    issue = Issue.generate!(:subject => "�")
2352 2349
    ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
2353 2350
      with_settings :default_language => lang do
2354 2351
        get :show, :params => {
test/functional/repositories_bazaar_controller_test.rb
28 28
  REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
29 29
  REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
30 30
  PRJ_ID = 3
31
  CHAR_1_UTF8_HEX   = "\xc3\x9c".dup.force_encoding('UTF-8')
32 31

  
33 32
  def setup
34 33
    super
......
224 223
        assert_select "th.line-num", :text => '1' do
225 224
          assert_select "+ td.revision" do
226 225
            assert_select "a", :text => '2'
227
            assert_select "+ td.author", :text => "test #{CHAR_1_UTF8_HEX}" do
226
            assert_select "+ td.author", :text => "test Ü" do
228 227
              assert_select "+ td",
229 228
                            :text => "author non ASCII test"
230 229
            end
test/functional/repositories_filesystem_controller_test.rb
112 112
               "when Encoding.default_external is not UTF-8. " +
113 113
               "Current value is '#{Encoding.default_external.to_s}'"
114 114
        else
115
          str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
116
          assert_select 'tr#L3 td.line-code', :text => /#{str_japanese}/
115
          assert_select 'tr#L3 td.line-code', :text => /日本語/
117 116
        end
118 117
      end
119 118
    end
test/functional/repositories_git_controller_test.rb
28 28
  REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
29 29
  REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30
  PRJ_ID     = 3
31
  CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
32
  FELIX_HEX  = "Felix Sch\xC3\xA4fer".force_encoding('UTF-8')
33 31
  NUM_REV = 28
34 32

  
35 33
  ## Git, Mercurial and CVS path encodings are binary.
......
65 63
            :is_default => '0',
66 64
            :identifier => 'test-create',
67 65
            :report_last_commit => '1',
68
                                 
66

  
69 67
          }
70 68
        }
71 69
    end
......
79 77
        :id => repository.id,
80 78
        :repository => {
81 79
          :report_last_commit => '0'
82
          
80

  
83 81
        }
84 82
      }
85 83
    assert_response 302
......
269 267
            get :entry, :params => {
270 268
                :id => PRJ_ID,
271 269
                :repository_id => @repository.id,
272
              :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
270
              :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
273 271
              :rev => r1
274 272
              }
275 273
            assert_response :success
276
            assert_select 'tr#L1 td.line-code', :text => /test-#{CHAR_1_HEX}.txt/
274
            assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
277 275
          end
278 276
        end
279 277
      end
......
440 438
                }
441 439
              assert_response :success
442 440
              assert_select 'table' do
443
                assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{CHAR_1_HEX}.txt/
444
                assert_select 'tbody td.diff_in', :text => /test-#{CHAR_1_HEX}.txt/
441
                assert_select 'thead th.filename', :text => /latin-1-dir\/test-Ü.txt/
442
                assert_select 'tbody td.diff_in', :text => /test-Ü.txt/
445 443
              end
446 444
            end
447 445
          end
......
568 566
            get :annotate, :params => {
569 567
                :id => PRJ_ID,
570 568
              :repository_id => @repository.id,
571
              :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
569
              :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
572 570
              :rev => r1
573 571
              }
574 572
            assert_select "th.line-num", :text => '1' do
......
576 574
                assert_select "a", :text => '57ca437c'
577 575
                assert_select "+ td.author", :text => "jsmith" do
578 576
                  assert_select "+ td",
579
                                :text => "test-#{CHAR_1_HEX}.txt"
577
                                :text => "test-Ü.txt"
580 578
                end
581 579
              end
582 580
            end
......
596 594
        assert_select "th.line-num", :text => '1' do
597 595
          assert_select "+ td.revision" do
598 596
            assert_select "a", :text => '83ca5fd5'
599
            assert_select "+ td.author", :text => FELIX_HEX do
597
            assert_select "+ td.author", :text => "Felix Schäfer" do
600 598
              assert_select "+ td",
601 599
                            :text => "And this is a file with a leading and trailing space..."
602 600
            end
test/functional/repositories_mercurial_controller_test.rb
26 26
           :repositories, :enabled_modules
27 27

  
28 28
  REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
29
  CHAR_1_HEX = "\xc3\x9c"
30 29
  PRJ_ID     = 3
31 30
  NUM_REV    = 34
32 31

  
......
43 42
                      )
44 43
    assert @repository
45 44
    @diff_c_support = true
46
    @char_1        = CHAR_1_HEX.dup.force_encoding('UTF-8')
47
    @tag_char_1    = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
48
    @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
49
    @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
50 45
  end
51 46

  
52 47
  if ruby19_non_utf8_pass
......
186 181
        assert_select 'table.entries tbody' do
187 182
          assert_select 'tr', 4
188 183
          assert_select 'tr.file td.filename a', :text => "make-latin-1-file.rb"
189
          assert_select 'tr.file td.filename a', :text => "test-#{@char_1}-1.txt"
190
          assert_select 'tr.file td.filename a', :text => "test-#{@char_1}-2.txt"
191
          assert_select 'tr.file td.filename a', :text => "test-#{@char_1}.txt"
184
          assert_select 'tr.file td.filename a', :text => "test-Ü-1.txt"
185
          assert_select 'tr.file td.filename a', :text => "test-Ü-2.txt"
186
          assert_select 'tr.file td.filename a', :text => "test-Ü.txt"
192 187
        end
193 188

  
194 189
        assert_select 'table.changesets tbody' do
......
221 216
      assert_equal NUM_REV, @repository.changesets.count
222 217
       [
223 218
          'default',
224
          @branch_char_1,
219
          'branch-Ü-01',
225 220
          'branch (1)[2]&,%.-3_4',
226
          @branch_char_0,
221
          'branch-Ü-00',
227 222
          'test_branch.latin-1',
228 223
          'test-branch-00',
229 224
      ].each do |bra|
......
245 240
      @project.reload
246 241
      assert_equal NUM_REV, @repository.changesets.count
247 242
       [
248
        @tag_char_1,
243
        'tag-Ü-00',
249 244
        'tag_test.00',
250 245
        'tag-init-revision'
251 246
      ].each do |tag|
......
287 282
        get :entry, :params => {
288 283
            :id => PRJ_ID,
289 284
            :repository_id => @repository.id,
290
          :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
285
          :path => repository_path_hash(['latin-1-dir', "test-Ü-2.txt"])[:param],
291 286
          :rev => r1
292 287
          }
293 288
        assert_response :success
......
301 296
          get :entry, :params => {
302 297
              :id => PRJ_ID,
303 298
              :repository_id => @repository.id,
304
            :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
299
            :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
305 300
            :rev => r1
306 301
            }
307 302
          assert_response :success
308
          assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
303
          assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
309 304
        end
310 305
      end
311 306
    end
......
395 390
              }
396 391
            assert_response :success
397 392
            assert_select 'table' do
398
              assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{@char_1}-2.txt/
393
              assert_select 'thead th.filename', :text => /latin-1-dir\/test-Ü-2.txt/
399 394
              assert_select 'tbody td.diff_in', :text => /It is written in Python/
400 395
            end
401 396
          end
......
478 473
        get :annotate, :params => {
479 474
            :id => PRJ_ID,
480 475
            :repository_id => @repository.id,
481
          :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
476
          :path => repository_path_hash(['latin-1-dir', "test-Ü-2.txt"])[:param],
482 477
          :rev => r1
483 478
          }
484 479
        assert_response :success
......
500 495
          get :annotate, :params => {
501 496
              :id => PRJ_ID,
502 497
              :repository_id => @repository.id,
503
            :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
498
            :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
504 499
            :rev => r1
505 500
            }
506
          assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
501
          assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
507 502
        end
508 503
      end
509 504
    end
test/functional/timelog_report_test.rb
260 260
  end
261 261

  
262 262
  def test_csv_big_5
263
    str_utf8  = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
264
    str_big5  = "\xa4@\xa4\xeb".force_encoding('Big5')
263
    str_big5  = (+"\xa4@\xa4\xeb").force_encoding('Big5')
265 264
    user = User.find_by_id(3)
266
    user.firstname = str_utf8
265
    user.firstname = "一月"
267 266
    user.lastname  = "test-lastname"
268 267
    assert user.save
269 268
    comments = "test_csv_big_5"
......
293 292
    assert_equal 'text/csv; header=present', @response.content_type
294 293
    lines = @response.body.chomp.split("\n")
295 294
    # Headers
296
    s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
297
    s2 = "\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
295
    s1 = (+"\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp").force_encoding('Big5')
296
    s2 = (+"\xa4u\xae\xc9\xc1`\xadp").force_encoding('Big5')
298 297
    assert_equal s1, lines.first
299 298
    # Total row
300 299
    assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
301 300
    assert_equal "#{s2},7.30,7.30", lines[2]
302 301

  
303
    str_tw = "Chinese/Traditional (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8')
304
    assert_equal str_tw, l(:general_lang_name)
302
    assert_equal 'Chinese/Traditional (繁體中文)', l(:general_lang_name)
305 303
    assert_equal 'Big5', l(:general_csv_encoding)
306 304
    assert_equal ',', l(:general_csv_separator)
307 305
    assert_equal '.', l(:general_csv_decimal_separator)
308 306
  end
309 307

  
310 308
  def test_csv_cannot_convert_should_be_replaced_big_5
311
    str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
312 309
    user = User.find_by_id(3)
313
    user.firstname = str_utf8
310
    user.firstname = "以内"
314 311
    user.lastname  = "test-lastname"
315 312
    assert user.save
316 313
    comments = "test_replaced"
......
340 337
    assert_equal 'text/csv; header=present', @response.content_type
341 338
    lines = @response.body.chomp.split("\n")
342 339
    # Headers
343
    s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
340
    s1 = (+"\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp").force_encoding('Big5')
344 341
    assert_equal s1, lines.first
345 342
    # Total row
346
    s2 = "\xa5H?".force_encoding('Big5')
343
    s2 = (+"\xa5H?").force_encoding('Big5')
347 344
    assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
348 345
  end
349 346

  
......
375 372
      assert_equal 'text/csv; header=present', @response.content_type
376 373
      lines = @response.body.chomp.split("\n")
377 374
      # Headers
378
      s1 = "Utilisateur;2011-11-11;Temps total".force_encoding('ISO-8859-1')
379
      s2 = "Temps total".force_encoding('ISO-8859-1')
375
      s1 = (+"Utilisateur;2011-11-11;Temps total").force_encoding('ISO-8859-1')
376
      s2 = (+"Temps total").force_encoding('ISO-8859-1')
380 377
      assert_equal s1, lines.first
381 378
      # Total row
382 379
      assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
383 380
      assert_equal "#{s2};7,30;7,30", lines[2]
384 381

  
385
      str_fr = "French (Fran\xc3\xa7ais)".force_encoding('UTF-8')
386
      assert_equal str_fr, l(:general_lang_name)
382
      assert_equal 'French (Français)', l(:general_lang_name)
387 383
      assert_equal 'ISO-8859-1', l(:general_csv_encoding)
388 384
      assert_equal ';', l(:general_csv_separator)
389 385
      assert_equal ',', l(:general_csv_decimal_separator)
test/helpers/application_helper_test.rb
37 37
  def setup
38 38
    super
39 39
    set_tmp_attachments_directory
40
    @russian_test = "\xd1\x82\xd0\xb5\xd1\x81\xd1\x82".force_encoding('UTF-8')
40
    @russian_test = 'тест'
41 41
  end
42 42

  
43 43
  test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do
......
1792 1792
  end
1793 1793

  
1794 1794
  def test_truncate_single_line_non_ascii
1795
    ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
1795
    ja = '日本語'
1796 1796
    result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10)
1797 1797
    assert_equal "#{ja} #{ja}...", result
1798 1798
    assert !result.html_safe?
test/integration/api_test/authentication_test.rb
112 112
  end
113 113

  
114 114
  def test_invalid_utf8_credentials_should_not_trigger_an_error
115
    invalid_utf8 = "\x82".force_encoding('UTF-8')
115
    invalid_utf8 = "\x82"
116 116
    assert !invalid_utf8.valid_encoding?
117 117
    assert_nothing_raised do
118 118
      get '/users/current.xml', :headers => credentials(invalid_utf8, "foo")
test/unit/attachment_test.rb
408 408
  end
409 409

  
410 410
  def test_latest_attach_should_not_error_with_string_with_invalid_encoding
411
    string = "width:50\xFE-Image.jpg".force_encoding('UTF-8')
411
    string = "width:50\xFE-Image.jpg"
412 412
    assert_equal false, string.valid_encoding?
413 413

  
414 414
    Attachment.latest_attach(Attachment.limit(2).to_a, string)
test/unit/changeset_test.rb
448 448

  
449 449
  def test_comments_should_be_converted_to_utf8
450 450
    proj = Project.find(3)
451
    # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
452
    str = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
451
    str = (+"Texte encod\xe9 en ISO-8859-1.").force_encoding("ASCII-8BIT")
453 452
    r = Repository::Bazaar.create!(
454 453
            :project      => proj,
455 454
            :url          => '/tmp/test/bazaar',
......
461 460
                      :scmid        => '12345',
462 461
                      :comments     => str)
463 462
    assert( c.save )
464
    str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1.".force_encoding("UTF-8")
465
    assert_equal str_utf8, c.comments
463
    assert_equal 'Texte encodé en ISO-8859-1.', c.comments
466 464
  end
467 465

  
468 466
  def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
469 467
    proj = Project.find(3)
470
    # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
471
    str1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("UTF-8")
472
    str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
468
    str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT")
473 469
    r = Repository::Bazaar.create!(
474 470
            :project      => proj,
475 471
            :url          => '/tmp/test/bazaar',
......
479 475
                      :committed_on => Time.now,
480 476
                      :revision     => '123',
481 477
                      :scmid        => '12345',
482
                      :comments     => str1,
478
                      :comments     => "Texte encod\xE9 en ISO-8859-1.",
483 479
                      :committer    => str2)
484 480
    assert( c.save )
485 481
    assert_equal "Texte encod? en ISO-8859-1.", c.comments
......
488 484

  
489 485
  def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
490 486
    proj = Project.find(3)
491
    str = "test\xb5\xfetest\xb5\xfe".force_encoding('ASCII-8BIT')
487
    str = (+"test\xb5\xfetest\xb5\xfe").force_encoding('ASCII-8BIT')
492 488
    r = Repository::Bazaar.create!(
493 489
            :project      => proj,
494 490
            :url          => '/tmp/test/bazaar',
......
504 500
  end
505 501

  
506 502
  def test_comments_should_be_converted_all_latin1_to_utf8
507
    s1 = "\xC2\x80"
508
    s2 = "\xc3\x82\xc2\x80"
503
    s1 = +"\xC2\x80"
504
    s2 = +"\xc3\x82\xc2\x80"
509 505
    s4 = s2.dup
510 506
    s3 = s1.dup
511 507
    s1.force_encoding('ASCII-8BIT')
......
530 526

  
531 527
  def test_invalid_utf8_sequences_in_paths_should_be_replaced
532 528
    proj = Project.find(3)
533
    str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
534
    str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
529
    str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT")
535 530
    r = Repository::Bazaar.create!(
536 531
            :project => proj,
537 532
            :url => '/tmp/test/bazaar',
......
547 542
    ch = Change.new(
548 543
                  :changeset     => cs,
549 544
                  :action        => "A",
550
                  :path          => str1,
545
                  :path          => "Texte encod\xE9 en ISO-8859-1",
551 546
                  :from_path     => str2,
552 547
                  :from_revision => "345")
553 548
    assert(ch.save)
test/unit/custom_field_test.rb
107 107

  
108 108
  def test_possible_values_should_return_utf8_encoded_strings
109 109
    field = CustomField.new
110
    s = "Value".force_encoding('BINARY')
110
    s = (+"Value").force_encoding('BINARY')
111 111
    field.possible_values = s
112 112
    assert_equal [s], field.possible_values
113 113
    assert_equal 'UTF-8', field.possible_values.first.encoding.name
test/unit/group_test.rb
58 58

  
59 59
  def test_blank_name_error_message_fr
60 60
    set_language_if_valid 'fr'
61
    str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
62 61
    g = Group.new
63 62
    assert !g.save
64
    assert_include str, g.errors.full_messages
63
    assert_include 'Nom doit être renseigné(e)', g.errors.full_messages
65 64
  end
66 65

  
67 66
  def test_group_roles_should_be_given_to_added_user
test/unit/lib/redmine/codeset_util_test.rb
23 23

  
24 24
  def test_to_utf8_by_setting_from_latin1
25 25
    with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
26
      s1 = "Texte encod\xc3\xa9".force_encoding("UTF-8")
27
      s2 = "Texte encod\xe9".force_encoding("ASCII-8BIT")
26
      s1 = 'Texte encodé'
27
      s2 = (+"Texte encod\xe9").force_encoding("ASCII-8BIT")
28 28
      s3 = s2.dup.force_encoding("UTF-8")
29 29
      assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
30 30
      assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
......
33 33

  
34 34
  def test_to_utf8_by_setting_from_euc_jp
35 35
    with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
36
      s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3".force_encoding("UTF-8")
37
      s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3".force_encoding("ASCII-8BIT")
36
      s1 = 'レッドマイン'
37
      s2 = (+"\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3").force_encoding("ASCII-8BIT")
38 38
      s3 = s2.dup.force_encoding("UTF-8")
39 39
      assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
40 40
      assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
......
43 43

  
44 44
  def test_to_utf8_by_setting_should_be_converted_all_latin1
45 45
    with_settings :repositories_encodings => 'ISO-8859-1' do
46
      s1 = "\xc3\x82\xc2\x80".force_encoding("UTF-8")
47
      s2 = "\xC2\x80".force_encoding("ASCII-8BIT")
46
      s1 = "Â\u0080"
47
      s2 = (+"\xC2\x80").force_encoding("ASCII-8BIT")
48 48
      s3 = s2.dup.force_encoding("UTF-8")
49 49
      assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
50 50
      assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
......
57 57
  end
58 58

  
59 59
  def test_to_utf8_by_setting_returns_ascii_as_utf8
60
    s1 = "ASCII".force_encoding("UTF-8")
60
    s1 = 'ASCII'
61 61
    s2 = s1.dup.force_encoding("ISO-8859-1")
62 62
    str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
63 63
    str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
......
69 69

  
70 70
  def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped
71 71
    with_settings :repositories_encodings => '' do
72
      # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
73
      s1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
72
      s1 = (+"Texte encod\xe9 en ISO-8859-1.").force_encoding("ASCII-8BIT")
74 73
      str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
75 74
      assert str.valid_encoding?
76 75
      assert_equal "UTF-8", str.encoding.to_s
......
80 79

  
81 80
  def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis
82 81
    with_settings :repositories_encodings => 'ISO-2022-JP' do
83
      s1 = "test\xb5\xfetest\xb5\xfe".force_encoding("ASCII-8BIT")
82
      s1 = (+"test\xb5\xfetest\xb5\xfe").force_encoding("ASCII-8BIT")
84 83
      str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
85 84
      assert str.valid_encoding?
86 85
      assert_equal "UTF-8", str.encoding.to_s
......
89 88
  end
90 89

  
91 90
  test "#replace_invalid_utf8 should replace invalid utf8" do
92
    s1 = "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xE3\x81\xFF".force_encoding("UTF-8")
91
    s1 = "こんにち\xE3\x81\xFF"
93 92
    s2 = Redmine::CodesetUtil.replace_invalid_utf8(s1)
94 93
    assert s2.valid_encoding?
95 94
    assert_equal "UTF-8", s2.encoding.to_s
96
    assert_equal "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1??".force_encoding("UTF-8"), s2
95
    assert_equal 'こんにち??', s2
97 96
  end
98 97

  
99 98
  test "#to_utf8 should replace invalid non utf8" do
100
    s1 = "\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4".force_encoding("EUC-JP")
99
    s1 = (+"\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4").force_encoding("EUC-JP")
101 100
    s2 = Redmine::CodesetUtil.to_utf8(s1, "EUC-JP")
102 101
    assert s2.valid_encoding?
103 102
    assert_equal "UTF-8", s2.encoding.to_s
104
    assert_equal "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1?".force_encoding("UTF-8"), s2
103
    assert_equal 'こんにち?', s2
105 104
  end
106 105
end
test/unit/lib/redmine/export/csv_test.rb
21 21

  
22 22
class CsvTest < ActiveSupport::TestCase
23 23
  include Redmine::I18n
24
  BOM = "\xEF\xBB\xBF".force_encoding('UTF-8')
25 24

  
26 25
  def test_should_include_bom_when_utf8_encoded
27 26
    with_locale 'sk' do
28 27
      string = Redmine::Export::CSV.generate {|csv| csv << %w(Foo Bar)}
29 28
      assert_equal 'UTF-8', string.encoding.name
30
      assert string.starts_with?(BOM)
29
      assert string.starts_with?("\xEF\xBB\xBF")
31 30
    end
32 31
  end
33 32

  
test/unit/lib/redmine/export/pdf_test.rb
29 29
  end
30 30

  
31 31
  def test_rdm_pdf_iconv_cannot_convert_ja_cp932
32
    utf8_txt_1  = "\xe7\x8b\x80\xe6\x85\x8b"
33
    utf8_txt_2  = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
34
    utf8_txt_3  = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
32
    utf8_txt_1  = '狀態'
33
    utf8_txt_2  = '狀態狀'
34
    utf8_txt_3  = '狀狀態狀'
35 35
    ["CP932", "SJIS"].each do |encoding|
36 36
      txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
37 37
      txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
38 38
      txt_3 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
39
      assert_equal "?\x91\xd4".force_encoding("ASCII-8BIT"), txt_1
40
      assert_equal "?\x91\xd4?".force_encoding("ASCII-8BIT"), txt_2
41
      assert_equal "??\x91\xd4?".force_encoding("ASCII-8BIT"), txt_3
39
      assert_equal (+"?\x91\xd4").force_encoding("ASCII-8BIT"), txt_1
40
      assert_equal (+"?\x91\xd4?").force_encoding("ASCII-8BIT"), txt_2
41
      assert_equal (+"??\x91\xd4?").force_encoding("ASCII-8BIT"), txt_3
42 42
      assert_equal "ASCII-8BIT", txt_1.encoding.to_s
43 43
      assert_equal "ASCII-8BIT", txt_2.encoding.to_s
44 44
      assert_equal "ASCII-8BIT", txt_3.encoding.to_s
......
46 46
  end
47 47

  
48 48
  def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en
49
    str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
50
    str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
49
    str1 = "Texte encod\xE9 en ISO-8859-1"
50
    str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT")
51 51
    txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, 'UTF-8')
52 52
    txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, 'UTF-8')
53 53
    assert_equal "ASCII-8BIT", txt_1.encoding.to_s
......
57 57
  end
58 58

  
59 59
  def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja
60
    str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
61
    str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
60
    str1 = "Texte encod\xE9 en ISO-8859-1"
61
    str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT")
62 62
    encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
63 63
    txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding)
64 64
    txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding)
......
72 72
    ["CP932", "SJIS"].each do |encoding|
73 73
      set_fixtures_attachments_directory
74 74

  
75
      str2 = "\x83e\x83X\x83g".force_encoding("ASCII-8BIT")
75
      str2 = (+"\x83e\x83X\x83g").force_encoding("ASCII-8BIT")
76 76

  
77 77
      a1 = Attachment.find(17)
78 78
      a2 = Attachment.find(19)
test/unit/lib/redmine/i18n_test.rb
70 70
        end
71 71
        assert l('date.day_names').is_a?(Array)
72 72
        assert_equal 7, l('date.day_names').size
73
  
73

  
74 74
        assert l('date.month_names').is_a?(Array)
75 75
        assert_equal 13, l('date.month_names').size
76 76
      end
......
165 165
    set_language_if_valid 'bs'
166 166
    assert_equal "KM -1000,20", number_to_currency(-1000.2)
167 167
    set_language_if_valid 'de'
168
    euro_sign = "\xe2\x82\xac".force_encoding('UTF-8')
169
    assert_equal "-1000,20 #{euro_sign}", number_to_currency(-1000.2)
168
    assert_equal '-1000,20 €', number_to_currency(-1000.2)
170 169
  end
171 170

  
172 171
  def test_lu_should_not_error_when_user_language_is_an_empty_string
......
191 190
    assert_nil options.detect {|option| option.size != 2}
192 191
    assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)}
193 192
    assert_include ["English", "en"], options
194
    ja = "Japanese (\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e)".force_encoding('UTF-8')
195
    assert_include [ja, "ja"], options
193
    assert_include ['Japanese (日本語)', "ja"], options
196 194
  end
197 195

  
198 196
  def test_languages_options_should_return_strings_with_utf8_encoding
......
243 241

  
244 242
  def test_utf8
245 243
    set_language_if_valid 'ja'
246
    str_ja_yes  = "\xe3\x81\xaf\xe3\x81\x84".force_encoding('UTF-8')
247 244
    i18n_ja_yes = l(:general_text_Yes)
248
    assert_equal str_ja_yes, i18n_ja_yes
245
    assert_equal 'はい', i18n_ja_yes
249 246
    assert_equal "UTF-8", i18n_ja_yes.encoding.to_s
250 247
  end
251 248

  
252 249
  def test_traditional_chinese_locale
253 250
    set_language_if_valid 'zh-TW'
254
    str_tw = "Chinese/Traditional (\xE7\xB9\x81\xE9\xAB\x94\xE4\xB8\xAD\xE6\x96\x87)".force_encoding('UTF-8')
255
    assert_equal str_tw, l(:general_lang_name)
251
    assert_equal 'Chinese/Traditional (繁體中文)', l(:general_lang_name)
256 252
  end
257 253

  
258 254
  def test_french_locale
259 255
    set_language_if_valid 'fr'
260
    str_fr = "French (Fran\xc3\xa7ais)".force_encoding('UTF-8')
261
    assert_equal str_fr, l(:general_lang_name)
256
    assert_equal 'French (Français)', l(:general_lang_name)
262 257
  end
263 258
end
test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
22 22
class GitAdapterTest < ActiveSupport::TestCase
23 23
  REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
24 24

  
25
  FELIX_HEX  = "Felix Sch\xC3\xA4fer"
26
  CHAR_1_HEX = "\xc3\x9c"
27

  
28 25
  ## Git, Mercurial and CVS path encodings are binary.
29 26
  ## Subversion supports URL encoding for path.
30 27
  ## Redmine Mercurial adapter and extension use URL encoding.
......
60 57
                    'ISO-8859-1'
61 58
                 )
62 59
      assert @adapter
63
      @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8')
64
      @str_felix_hex  = FELIX_HEX.dup.force_encoding('ASCII-8BIT')
60
      @char_1 = 'Ü'
61
      @str_felix_hex  = (+"Felix Sch\xC3\xA4fer").force_encoding('ASCII-8BIT')
65 62
    end
66 63

  
67 64
    def test_scm_version
......
80 77
      end
81 78
      assert_equal 6, brs.length
82 79
      br_issue_8857 = brs[0]
83
      assert_equal 'issue-8857', br_issue_8857.to_s 
80
      assert_equal 'issue-8857', br_issue_8857.to_s
84 81
      assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision
85 82
      assert_equal br_issue_8857.scmid, br_issue_8857.revision
86 83
      assert_equal false, br_issue_8857.is_default
87 84
      br_latin_1_path = brs[1]
88
      assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s 
85
      assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s
89 86
      assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision
90 87
      assert_equal br_latin_1_path.scmid, br_latin_1_path.revision
91 88
      assert_equal false, br_latin_1_path.is_default
test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb
27 27
  HgCommandArgumentError = Redmine::Scm::Adapters::MercurialAdapter::HgCommandArgumentError
28 28

  
29 29
  REPOSITORY_PATH = repository_path('mercurial')
30
  CHAR_1_HEX = "\xc3\x9c"
31 30

  
32 31
  if File.directory?(REPOSITORY_PATH)
33 32
    def setup
......
44 43
                            nil,
45 44
                           'ISO-8859-1')
46 45
      @diff_c_support = true
47
      @char_1        = CHAR_1_HEX.dup.force_encoding('UTF-8')
48
      @tag_char_1    = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
49
      @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
50
      @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
46
      @char_1        = 'Ü'
47
      @tag_char_1    = 'tag-Ü-00'
48
      @branch_char_0 = 'branch-Ü-00'
49
      @branch_char_1 = 'branch-Ü-01'
51 50
    end
52 51

  
53 52
    def test_hgversion
test/unit/lib/redmine/unified_diff_test.rb
274 274
  end
275 275

  
276 276
  def test_utf8_ja
277
    ja = "  text_tip_issue_end_day: "
278
    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>".force_encoding('UTF-8')
279 277
    with_settings :repositories_encodings => '' do
280 278
      diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ja.diff'), :type => 'inline')
281 279
      assert_equal 1, diff.size
282 280
      assert_equal 12, diff.first.size
283
      assert_equal ja, diff.first[4].html_line_left
281
      assert_equal '  text_tip_issue_end_day: この日に終了する<span>タスク</span>', diff.first[4].html_line_left
284 282
    end
285 283
  end
286 284

  
287 285
  def test_utf8_ru
288
    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;".force_encoding('UTF-8')
289 286
    with_settings :repositories_encodings => '' do
290 287
      diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ru.diff'), :type => 'inline')
291 288
      assert_equal 1, diff.size
292 289
      assert_equal 8, diff.first.size
293
      assert_equal ru, diff.first[3].html_line_left
290
      assert_equal '        other: &quot;около %{count} час<span>а</span>&quot;', diff.first[3].html_line_left
294 291
    end
295 292
  end
296 293

  
......
329 326
  end
330 327

  
331 328
  def test_offset_range_japanese_1
332
    ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span></span>".force_encoding('UTF-8')
333
    ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x9e</span>".force_encoding('UTF-8')
334 329
    with_settings :repositories_encodings => '' do
335 330
      diff = Redmine::UnifiedDiff.new(
336 331
               read_diff_fixture('issue-13644-1.diff'), :type => 'sbs')
337 332
      assert_equal 1, diff.size
338 333
      assert_equal 3, diff.first.size
339
      assert_equal ja1, diff.first[1].html_line_left
340
      assert_equal ja2, diff.first[1].html_line_right
334
      assert_equal '日本<span></span>', diff.first[1].html_line_left
335
      assert_equal '日本<span>語</span>', diff.first[1].html_line_right
341 336
    end
342 337
  end
343 338

  
344 339
  def test_offset_range_japanese_2
345
    ja1 = "<span></span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8')
346
    ja2 = "<span>\xe3\x81\xab\xe3\x81\xa3\xe3\x81\xbd\xe3\x82\x93</span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8')
347 340
    with_settings :repositories_encodings => '' do
348 341
      diff = Redmine::UnifiedDiff.new(
349 342
               read_diff_fixture('issue-13644-2.diff'), :type => 'sbs')
350 343
      assert_equal 1, diff.size
351 344
      assert_equal 3, diff.first.size
352
      assert_equal ja1, diff.first[1].html_line_left
353
      assert_equal ja2, diff.first[1].html_line_right
345
      assert_equal '<span></span>日本', diff.first[1].html_line_left
346
      assert_equal '<span>にっぽん</span>日本', diff.first[1].html_line_right
354 347
    end
355 348
  end
356 349

  
357 350
  def test_offset_range_japanese_3
358 351
    # UTF-8 The 1st byte differs.
359
    ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8')
360
    ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe5\xa8\x98</span>".force_encoding('UTF-8')
361 352
    with_settings :repositories_encodings => '' do
362 353
      diff = Redmine::UnifiedDiff.new(
363 354
               read_diff_fixture('issue-13644-3.diff'), :type => 'sbs')
364 355
      assert_equal 1, diff.size
365 356
      assert_equal 3, diff.first.size
366
      assert_equal ja1, diff.first[1].html_line_left
367
      assert_equal ja2, diff.first[1].html_line_right
357
      assert_equal '日本<span>記</span>', diff.first[1].html_line_left
358
      assert_equal '日本<span>娘</span>', diff.first[1].html_line_right
368 359
    end
369 360
  end
370 361

  
371 362
  def test_offset_range_japanese_4
372
    # UTF-8 The 2nd byte differs. 
373
    ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8')
374
    ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>".force_encoding('UTF-8')
363
    # UTF-8 The 2nd byte differs.
375 364
    with_settings :repositories_encodings => '' do
376 365
      diff = Redmine::UnifiedDiff.new(
377 366
               read_diff_fixture('issue-13644-4.diff'), :type => 'sbs')
378 367
      assert_equal 1, diff.size
379 368
      assert_equal 3, diff.first.size
380
      assert_equal ja1, diff.first[1].html_line_left
381
      assert_equal ja2, diff.first[1].html_line_right
369
      assert_equal '日本<span>記</span>', diff.first[1].html_line_left
370
      assert_equal '日本<span>誘</span>', diff.first[1].html_line_right
382 371
    end
383 372
  end
384 373

  
385 374
  def test_offset_range_japanese_5
386
    # UTF-8 The 2nd byte differs. 
387
    ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>ok".force_encoding('UTF-8')
388
    ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>ok".force_encoding('UTF-8')
375
    # UTF-8 The 2nd byte differs.
389 376
    with_settings :repositories_encodings => '' do
390 377
      diff = Redmine::UnifiedDiff.new(
391 378
               read_diff_fixture('issue-13644-5.diff'), :type => 'sbs')
392 379
      assert_equal 1, diff.size
393 380
      assert_equal 3, diff.first.size
394
      assert_equal ja1, diff.first[1].html_line_left
395
      assert_equal ja2, diff.first[1].html_line_right
381
      assert_equal '日本<span>記</span>ok', diff.first[1].html_line_left
382
      assert_equal '日本<span>誘</span>ok', diff.first[1].html_line_right
396 383
    end
397 384
  end
398 385

  
test/unit/mail_handler_test.rb
515 515
  end
516 516

  
517 517
  def test_add_issue_with_japanese_keywords
518
    ja_dev = "\xe9\x96\x8b\xe7\x99\xba".force_encoding('UTF-8')
519
    tracker = Tracker.generate!(:name => ja_dev)
518
    tracker = Tracker.generate!(:name => '開発')
520 519
    Project.find(1).trackers << tracker
521 520
    issue = submit_email(
522 521
              'japanese_keywords_iso_2022_jp.eml',
......
550 549
            )
551 550
    assert_kind_of Issue, issue
552 551
    assert_equal 1, issue.attachments.size
553
    ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
554 552
    attachment = issue.attachments.first
555
    assert_equal ja, attachment.filename
553
    assert_equal 'テスト.txt', attachment.filename
556 554
    assert_equal 5, attachment.filesize
557 555
    assert File.exist?(attachment.diskfile)
558 556
    assert_equal 5, File.size(attachment.diskfile)
......
565 563
              :issue => {:project => 'ecookbook'}
566 564
            )
567 565
    assert_kind_of Issue, issue
568
    description = "\xD0\x97\xD0\xB4\xD1\x80\xD0\xB0\xD0\xB2\xD1\x81\xD1\x82\xD0\xB2\xD1\x83\xD0\xB9\xD1\x82\xD0\xB5?".force_encoding('UTF-8')
569
    assert_equal description, issue.description
566
    assert_equal 'Здравствуйте?', issue.description
570 567
  end
571 568

  
572 569
  def test_gmail_with_attachment_ja
......
576 573
            )
577 574
    assert_kind_of Issue, issue
578 575
    assert_equal 1, issue.attachments.size
579
    ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt".force_encoding('UTF-8')
580 576
    attachment = issue.attachments.first
581
    assert_equal ja, attachment.filename
577
    assert_equal 'テスト.txt', attachment.filename
582 578
    assert_equal 5, attachment.filesize
583 579
    assert File.exist?(attachment.diskfile)
584 580
    assert_equal 5, File.size(attachment.diskfile)
......
592 588
            )
593 589
    assert_kind_of Issue, issue
594 590
    assert_equal 1, issue.attachments.size
595
    u = "".force_encoding('UTF-8')
596
    u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
591
    u = +''
592
    u1 = 'ÄäÖöÜü'
597 593
    11.times { u << u1 }
598 594
    attachment = issue.attachments.first
599 595
    assert_equal "#{u}.png", attachment.filename
......
610 606
            )
611 607
    assert_kind_of Issue, issue
612 608
    assert_equal 1, issue.attachments.size
613
    u = "".force_encoding('UTF-8')
614
    u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc".force_encoding('UTF-8')
609
    u = +''
610
    u1 = 'ÄäÖöÜü'
615 611
    11.times { u << u1 }
616 612
    attachment = issue.attachments.first
617 613
    assert_equal "#{u}.txt", attachment.filename
......
633 629
    assert_equal 19, attachment.filesize
634 630
    assert File.exist?(attachment.diskfile)
635 631
    assert_equal 19, File.size(attachment.diskfile)
636
    content = "p\xF8\xEDli\xB9 \xBEluou\xE8k\xFD k\xF9n".force_encoding('CP852')
632
    content = (+"p\xF8\xEDli\xB9 \xBEluou\xE8k\xFD k\xF9n").force_encoding('CP852')
637 633
    assert_equal content, File.read(attachment.diskfile).force_encoding('CP852')
638 634
  end
639 635

  
......
686 682
              'subject_as_iso-8859-1.eml',
687 683
              :issue => {:project => 'ecookbook'}
688 684
            )
689
    str = "Testmail from Webmail: \xc3\xa4 \xc3\xb6 \xc3\xbc...".force_encoding('UTF-8')
690 685
    assert_kind_of Issue, issue
691
    assert_equal str, issue.subject
686
    assert_equal 'Testmail from Webmail: ä ö ü...', issue.subject
692 687
  end
693 688

  
694 689
  def test_quoted_printable_utf8
......
697 692
              :issue => {:project => 'ecookbook'}
698 693
            )
699 694
    assert_kind_of Issue, issue
700
    str = "Freundliche Gr\xc3\xbcsse".force_encoding('UTF-8')
701
    assert_equal str, issue.description
695
    assert_equal 'Freundliche Grüsse', issue.description
702 696
  end
703 697

  
704 698
  def test_gmail_iso8859_2
......
707 701
              :issue => {:project => 'ecookbook'}
708 702
            )
709 703
    assert_kind_of Issue, issue
710
    str = "Na \xc5\xa1triku se su\xc5\xa1i \xc5\xa1osi\xc4\x87.".force_encoding('UTF-8')
711
    assert issue.description.include?(str)
704
    assert issue.description.include?('Na štriku se suši šosić.')
712 705
  end
713 706

  
714 707
  def test_add_issue_with_japanese_subject
......
717 710
              :issue => {:project => 'ecookbook'}
718 711
            )
719 712
    assert_kind_of Issue, issue
720
    ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
721
    assert_equal ja, issue.subject
713
    assert_equal 'テスト', issue.subject
722 714
  end
723 715

  
724 716
  def test_add_issue_with_korean_body
725
    # Make sure mail bodies with a charset unknown to Ruby
726
    # but known to the Mail gem 2.5.4 are handled correctly
727
    kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4.".force_encoding('UTF-8')
728 717
    issue = submit_email(
729 718
            'body_ks_c_5601-1987.eml',
730 719
            :issue => {:project => 'ecookbook'}
731 720
          )
732 721
    assert_kind_of Issue, issue
733
    assert_equal kr, issue.description
722
    assert_equal '고맙습니다.', issue.description
734 723
  end
735 724

  
736 725
  def test_add_issue_with_no_subject_header
......
748 737
              :issue => {:project => 'ecookbook'}
749 738
            )
750 739
    assert_kind_of Issue, issue
751
    ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
752
    assert_equal ja, issue.subject
740
    assert_equal 'Re: テスト', issue.subject
753 741
  end
754 742

  
755 743
  def test_add_issue_with_iso_2022_jp_ms_subject
......
1187 1175
    end
1188 1176
    user = User.order('id DESC').first
1189 1177
    assert_equal "foo@example.org", user.mail
1190
    str1 = "\xc3\x84\xc3\xa4".force_encoding('UTF-8')
1191
    str2 = "\xc3\x96\xc3\xb6".force_encoding('UTF-8')
1192
    assert_equal str1, user.firstname
1193
    assert_equal str2, user.lastname
1178
    assert_equal 'Ää', user.firstname
1179
    assert_equal 'Öö', user.lastname
1194 1180
  end
1195 1181

  
1196 1182
  def test_new_user_with_fullname_in_parentheses
test/unit/member_test.rb
88 88
    member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
89 89
    assert !member.save
90 90
    assert_include I18n.translate('activerecord.errors.messages.empty'), member.errors[:role]
91
    assert_equal "R\xc3\xb4le doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8'),
91
    assert_equal 'Rôle doit être renseigné(e)',
92 92
      [member.errors.full_messages].flatten.join
93 93
  end
94 94

  
test/unit/query_test.rb
1830 1830
  def test_label_for_fr
1831 1831
    set_language_if_valid 'fr'
1832 1832
    q = IssueQuery.new
1833
    assert_equal "Assign\xc3\xa9 \xc3\xa0".force_encoding('UTF-8'), q.label_for('assigned_to_id')
1833
    assert_equal 'Assigné à', q.label_for('assigned_to_id')
1834 1834
  end
1835 1835

  
1836 1836
  def test_editable_by
test/unit/repository_bazaar_test.rb
46 46
  RUN_LATIN1_OUTPUT_TEST = (RUBY_PLATFORM != 'java' &&
47 47
                             Encoding.locale_charmap == "ISO-8859-1")
48 48

  
49
  CHAR_1_UTF8_HEX   = "\xc3\x9c".force_encoding('UTF-8')
50
  CHAR_1_LATIN1_HEX = "\xdc".force_encoding('ASCII-8BIT')
49
  CHAR_1_UTF8_HEX   = 'Ü'
50
  CHAR_1_LATIN1_HEX = (+"\xdc").force_encoding('ASCII-8BIT')
51 51

  
52 52
  def setup
53 53
    User.current = nil
......
72 72

  
73 73
  def test_blank_path_to_repository_error_message_fr
74 74
    set_language_if_valid 'fr'
75
    str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
76 75
    repo = Repository::Bazaar.new(
77 76
                          :project      => @project,
78 77
                          :url          => "",
......
80 79
                          :log_encoding => 'UTF-8'
81 80
                        )
82 81
    assert !repo.save
83
    assert_include str, repo.errors.full_messages
82
    assert_include 'Chemin du dépôt doit être renseigné(e)', repo.errors.full_messages
84 83
  end
85 84

  
86 85
  if File.directory?(REPOSITORY_PATH_TRUNK)
test/unit/repository_cvs_test.rb
55 55

  
56 56
  def test_blank_module_error_message_fr
57 57
    set_language_if_valid 'fr'
58
    str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
59 58
    repo = Repository::Cvs.new(
60 59
                          :project       => @project,
61 60
                          :identifier    => 'test',
......
65 64
                          :root_url      => REPOSITORY_PATH
66 65
                        )
67 66
    assert !repo.save
68
    assert_include str, repo.errors.full_messages
67
    assert_include 'Module doit être renseigné(e)', repo.errors.full_messages
69 68
  end
70 69

  
71 70
  def test_blank_cvsroot_error_message
......
83 82

  
84 83
  def test_blank_cvsroot_error_message_fr
85 84
    set_language_if_valid 'fr'
86
    str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
87 85
    repo = Repository::Cvs.new(
88 86
                          :project       => @project,
89 87
                          :identifier    => 'test',
......
93 91
                          :root_url      => ''
94 92
                        )
95 93
    assert !repo.save
96
    assert_include str, repo.errors.full_messages
94
    assert_include 'CVSROOT doit être renseigné(e)', repo.errors.full_messages
97 95
  end
98 96

  
99 97
  def test_root_url_should_be_validated_against_regexp_set_in_configuration
test/unit/repository_filesystem_test.rb
50 50

  
51 51
  def test_blank_root_directory_error_message_fr
52 52
    set_language_if_valid 'fr'
53
    str = "R\xc3\xa9pertoire racine doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
54 53
    repo = Repository::Filesystem.new(
55 54
                          :project      => @project,
56 55
                          :url          => "",
......
58 57
                          :path_encoding => ''
59 58
                        )
60 59
    assert !repo.save
61
    assert_include str, repo.errors.full_messages
60
    assert_include 'Répertoire racine doit être renseigné(e)', repo.errors.full_messages
62 61
  end
63 62

  
64 63
  if File.directory?(REPOSITORY_PATH)
test/unit/repository_git_test.rb
30 30
  NUM_REV = 28
31 31
  NUM_HEAD = 6
32 32

  
33
  FELIX_HEX  = "Felix Sch\xC3\xA4fer".force_encoding('UTF-8')
34
  CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
35

  
36 33
  ## Git, Mercurial and CVS path encodings are binary.
37 34
  ## Subversion supports URL encoding for path.
38 35
  ## Redmine Mercurial adapter and extension use URL encoding.
......
96 93

  
97 94
  def test_blank_path_to_repository_error_message_fr
98 95
    set_language_if_valid 'fr'
99
    str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
100 96
    repo = Repository::Git.new(
101 97
                          :project      => @project,
102 98
                          :url          => "",
......
104 100
                          :path_encoding => ''
105 101
                        )
106 102
    assert !repo.save
107
    assert_include str, repo.errors.full_messages
103
    assert_include 'Chemin du dépôt doit être renseigné(e)', repo.errors.full_messages
108 104
  end
109 105

  
110 106
  if File.directory?(REPOSITORY_PATH)
......
470 466
      else
471 467
        # latin-1 encoding path
472 468
        changesets = @repository.latest_changesets(
473
                      "latin-1-dir/test-#{CHAR_1_HEX}-2.txt", '64f1f3e89')
469
                      'latin-1-dir/test-Ü-2.txt', '64f1f3e89')
474 470
        assert_equal [
475 471
              '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
476 472
              '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
477 473
          ], changesets.collect(&:revision)
478 474

  
479 475
        changesets = @repository.latest_changesets(
480
                    "latin-1-dir/test-#{CHAR_1_HEX}-2.txt", '64f1f3e89', 1)
476
                    'latin-1-dir/test-Ü-2.txt', '64f1f3e89', 1)
481 477
        assert_equal [
482 478
              '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
483 479
          ], changesets.collect(&:revision)
......
495 491
        @project.reload
496 492
        assert_equal NUM_REV, @repository.changesets.count
497 493
        changesets = @repository.latest_changesets(
498
                    "latin-1-dir/test-#{CHAR_1_HEX}-subdir", '1ca7f5ed')
494
                    'latin-1-dir/test-Ü-subdir', '1ca7f5ed')
499 495
        assert_equal [
500 496
              '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
501 497
          ], changesets.collect(&:revision)
......
560 556
      assert_equal NUM_REV, @repository.changesets.count
561 557
      c = @repository.changesets.find_by_revision(
562 558
                        'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
563
      assert_equal "#{FELIX_HEX} <felix@fachschaften.org>", c.committer
559
      assert_equal 'Felix Schäfer <felix@fachschaften.org>', c.committer
564 560
    end
565 561

  
566 562
    def test_previous
test/unit/repository_mercurial_test.rb
27 27
  REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
28 28
  NUM_REV = 34
29 29

  
30
  CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
31
  BRANCH_CHAR_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
32

  
33 30
  def setup
34 31
    User.current = nil
35 32
    @project    = Project.find(3)
......
54 51

  
55 52
  def test_blank_path_to_repository_error_message_fr
56 53
    set_language_if_valid 'fr'
57
    str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
58 54
    repo = Repository::Mercurial.new(
59 55
                          :project      => @project,
60 56
                          :url          => "",
......
62 58
                          :path_encoding => ''
63 59
                        )
64 60
    assert !repo.save
65
    assert_include str, repo.errors.full_messages
61
    assert_include 'Chemin du dépôt doit être renseigné(e)', repo.errors.full_messages
66 62
  end
67 63

  
68 64
  if File.directory?(REPOSITORY_PATH)
......
356 352
      assert_equal NUM_REV, @repository.changesets.count
357 353

  
358 354
      if @repository.scm.class.client_version_above?([1, 6])
359
        changesets = @repository.latest_changesets('', BRANCH_CHAR_1)
355
        changesets = @repository.latest_changesets('', 'branch-Ü-01')
360 356
        assert_equal %w|27 26|, changesets.collect(&:revision)
361 357
      end
362 358

  
363
      changesets = @repository.latest_changesets("latin-1-dir/test-#{CHAR_1_HEX}-subdir", BRANCH_CHAR_1)
359
      changesets = @repository.latest_changesets('latin-1-dir/test-Ü-subdir', 'branch-Ü-01')
364 360
      assert_equal %w|27|, changesets.collect(&:revision)
365 361
    end
366 362

  
......
423 419
      scmid3 = scmid_for_assert(hex3, is_short_scmid)
424 420
      assert_equal 1, c3.size
425 421
      assert_equal 'A', c3[0].action
426
      assert_equal "/latin-1-dir/test-#{CHAR_1_HEX}-1.txt",  c3[0].path
427
      assert_equal "/latin-1-dir/test-#{CHAR_1_HEX}.txt",    c3[0].from_path
422
      assert_equal '/latin-1-dir/test-Ü-1.txt',  c3[0].path
423
      assert_equal '/latin-1-dir/test-Ü.txt',    c3[0].from_path
428 424
      assert_equal scmid3, c3[0].from_revision
429 425
    end
430 426
    private :assert_copied_files
test/unit/repository_subversion_test.rb
236 236

  
237 237
    def test_log_encoding_ignore_setting
238 238
      with_settings :commit_logs_encoding => 'windows-1252' do
239
        s2 = "\xc3\x82\xc2\x80".force_encoding('UTF-8')
239
        s2 = "Â\u0080"
240 240
        c = Changeset.new(:repository => @repository,
241 241
                          :comments   => s2,
242 242
                          :revision   => '123',
test/unit/repository_test.rb
60 60

  
61 61
  def test_blank_log_encoding_error_message_fr
62 62
    set_language_if_valid 'fr'
63
    str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
64 63
    repo = Repository::Bazaar.new(
65 64
                        :project      => Project.find(3),
66 65
                        :url          => "/test"
67 66
                      )
68 67
    assert !repo.save
69
    assert_include str, repo.errors.full_messages
68
    assert_include 'Encodage des messages de commit doit être renseigné(e)', repo.errors.full_messages
70 69
  end
71 70

  
72 71
  def test_create
......
287 286
                    :url => '/foo/bar/baz' )
288 287
    long_whitespace = "                                                "
289 288
    expected_comment = "This is a loooooooooooooooooooooooooooong comment"
290
    comment = "#{expected_comment}#{long_whitespace}\n"
289
    comment = +"#{expected_comment}#{long_whitespace}\n"
291 290
    3.times {comment << "#{long_whitespace}\n"}
292 291
    changeset = Changeset.new(
293 292
      :comments => comment, :commit_date => Time.now,
test/unit/wiki_test.rb
82 82
  end
83 83

  
84 84
  def test_titleize
85
    ja_test = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
85
    ja_test = 'テスト'
86 86
    assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
87 87
    assert_equal ja_test, Wiki.titleize(ja_test)
88 88
  end
    (1-1/1)