Project

General

Profile

Feature #32085 » 32085-allow-newline-as-separator-v2.patch

Yuichi HARADA, 2020-03-10 08:25

View differences:

app/models/attachment.rb
417 417
    extension = extension.downcase.sub(/\A\.+/, '')
418 418

  
419 419
    unless extensions.is_a?(Array)
420
      extensions = extensions.to_s.split(",").map(&:strip)
420
      extensions = extensions.to_s.split(/[\s,]+/)
421 421
    end
422 422
    extensions = extensions.map {|s| s.downcase.sub(/\A\.+/, '')}.reject(&:blank?)
423 423
    extensions.include?(extension)
app/models/mail_handler.rb
308 308

  
309 309
  # Returns false if the +attachment+ of the incoming email should be ignored
310 310
  def accept_attachment?(attachment)
311
    @excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(',').map(&:strip).reject(&:blank?)
311
    @excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(/[\s,]+/).reject(&:blank?)
312 312
    @excluded.each do |pattern|
313 313
      if Setting.mail_handler_enable_regex_excluded_filenames?
314 314
        regexp = %r{\A#{pattern}\z}i
test/unit/attachment_test.rb
139 139
  end
140 140

  
141 141
  def test_extension_should_be_validated_against_denied_extensions
142
    with_settings :attachment_extensions_denied => "txt, png" do
142
    with_settings :attachment_extensions_denied => "txt, png\r\ncsv" do
143 143
      a = Attachment.new(:container => Issue.find(1),
144 144
                         :file => mock_file_with_options(:original_filename => "test.jpeg"),
145 145
                         :author => User.find(1))
......
153 153
  end
154 154

  
155 155
  def test_valid_extension_should_be_case_insensitive
156
    with_settings :attachment_extensions_allowed => "txt, Png" do
156
    with_settings :attachment_extensions_allowed => "txt, Png\r\ncsv" do
157 157
      assert Attachment.valid_extension?(".pnG")
158 158
      assert !Attachment.valid_extension?(".jpeg")
159 159
    end
160
    with_settings :attachment_extensions_denied => "txt, Png" do
160
    with_settings :attachment_extensions_denied => "txt, Png\r\ncsv" do
161 161
      assert !Attachment.valid_extension?(".pnG")
162 162
      assert Attachment.valid_extension?(".jpeg")
163 163
    end
test/unit/mail_handler_test.rb
33 33
  FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
34 34

  
35 35
  def setup
36
    set_tmp_attachments_directory
36 37
    ActionMailer::Base.deliveries.clear
37 38
    Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
38 39
    User.current = nil
......
546 547
  end
547 548

  
548 549
  def test_add_issue_from_apple_mail
549
    set_tmp_attachments_directory
550 550
    issue = submit_email(
551 551
              'apple_mail_with_attachment.eml',
552 552
              :issue => {:project => 'ecookbook'}
......
563 563
  end
564 564

  
565 565
  def test_thunderbird_with_attachment_ja
566
    set_tmp_attachments_directory
567 566
    issue = submit_email(
568 567
              'thunderbird_with_attachment_ja.eml',
569 568
              :issue => {:project => 'ecookbook'}
......
588 587
  end
589 588

  
590 589
  def test_gmail_with_attachment_ja
591
    set_tmp_attachments_directory
592 590
    issue = submit_email(
593 591
              'gmail_with_attachment_ja.eml',
594 592
              :issue => {:project => 'ecookbook'}
......
604 602
  end
605 603

  
606 604
  def test_thunderbird_with_attachment_latin1
607
    set_tmp_attachments_directory
608 605
    issue = submit_email(
609 606
              'thunderbird_with_attachment_iso-8859-1.eml',
610 607
              :issue => {:project => 'ecookbook'}
......
623 620
  end
624 621

  
625 622
  def test_gmail_with_attachment_latin1
626
    set_tmp_attachments_directory
627 623
    issue = submit_email(
628 624
              'gmail_with_attachment_iso-8859-1.eml',
629 625
              :issue => {:project => 'ecookbook'}
......
642 638
  end
643 639

  
644 640
  def test_mail_with_attachment_latin2
645
    set_tmp_attachments_directory
646 641
    issue = submit_email(
647 642
              'ticket_with_text_attachment_iso-8859-2.eml',
648 643
              :issue => {:project => 'ecookbook'}
......
995 990
  end
996 991

  
997 992
  def test_reply_to_a_nonexistent_issue
998
    set_tmp_attachments_directory
999 993
    Issue.find(2).destroy
1000 994
    assert_no_difference 'Issue.count' do
1001 995
      assert_no_difference 'Journal.count' do
......
1157 1151
  end
1158 1152

  
1159 1153
  def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored
1160
    with_settings :mail_handler_excluded_filenames => "*.vcf,\n *.jpg" do
1154
    with_settings :mail_handler_excluded_filenames => "*.vcf,\n *.jpg\r\n*.csv" do
1161 1155
      issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
1162 1156
      assert issue.is_a?(Issue)
1163 1157
      assert !issue.new_record?
......
1166 1160
  end
1167 1161

  
1168 1162
  def test_attachments_that_match_mail_handler_excluded_filenames_by_regex_should_be_ignored
1169
    with_settings :mail_handler_excluded_filenames => '.+\.vcf,(pa|nut)ella\.jpg',
1163
    with_settings :mail_handler_excluded_filenames => ".+\\.vcf,(pa|nut)ella\\.jpg\r\n.+\\.csv",
1170 1164
                  :mail_handler_enable_regex_excluded_filenames => 1 do
1171 1165
      issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
1172 1166
      assert issue.is_a?(Issue)
(2-2/3)