Project

General

Profile

Defect #24616 » defect-24616.diff

fix + tests (generated from Pavel Rosický's contribution) - Go MAEDA, 2016-12-29 07:52

View differences:

lib/redmine/codeset_util.rb (working copy)
6 6
      return str if str.nil?
7 7
      str.force_encoding('UTF-8')
8 8
      if ! str.valid_encoding?
9
        str = str.encode("US-ASCII", :invalid => :replace,
10
              :undef => :replace, :replace => '?').encode("UTF-8")
9
        str = str.encode("UTF-8", :invalid => :replace,
10
              :undef => :replace, :replace => '?')
11 11
      end
12 12
      str
13 13
    end
......
27 27
      else
28 28
        str.force_encoding("UTF-8")
29 29
        if ! str.valid_encoding?
30
          str = str.encode("US-ASCII", :invalid => :replace,
31
                :undef => :replace, :replace => '?').encode("UTF-8")
30
          str = str.encode("UTF-8", :invalid => :replace,
31
                :undef => :replace, :replace => '?')
32 32
        end
33 33
      end
34 34
      str
test/unit/mail_handler_test.rb (working copy)
538 538
    assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
539 539
  end
540 540

  
541
  def test_invalid_utf8
542
    issue = submit_email(
543
              'invalid_utf8.eml',
544
              :issue => {:project => 'ecookbook'}
545
            )
546
    assert_kind_of Issue, issue
547
    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')
548
    assert_equal description, issue.description
549
  end
550

  
541 551
  def test_gmail_with_attachment_ja
542 552
    issue = submit_email(
543 553
              'gmail_with_attachment_ja.eml',
(2-2/2)