diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 627c1a181..f033affb7 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -417,7 +417,7 @@ class Attachment < ActiveRecord::Base extension = extension.downcase.sub(/\A\.+/, '') unless extensions.is_a?(Array) - extensions = extensions.to_s.split(",").map(&:strip) + extensions = extensions.to_s.split(/[\s,]+/) end extensions = extensions.map {|s| s.downcase.sub(/\A\.+/, '')}.reject(&:blank?) extensions.include?(extension) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index eccc93a2a..8ef5ed24b 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -308,7 +308,7 @@ class MailHandler < ActionMailer::Base # Returns false if the +attachment+ of the incoming email should be ignored def accept_attachment?(attachment) - @excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(',').map(&:strip).reject(&:blank?) + @excluded ||= Setting.mail_handler_excluded_filenames.to_s.split(/[\s,]+/).reject(&:blank?) @excluded.each do |pattern| if Setting.mail_handler_enable_regex_excluded_filenames? regexp = %r{\A#{pattern}\z}i diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index 831278634..2f8e7e113 100644 --- a/test/unit/attachment_test.rb +++ b/test/unit/attachment_test.rb @@ -153,11 +153,11 @@ class AttachmentTest < ActiveSupport::TestCase end def test_valid_extension_should_be_case_insensitive - with_settings :attachment_extensions_allowed => "txt, Png" do + with_settings :attachment_extensions_allowed => "txt\r\n Png" do assert Attachment.valid_extension?(".pnG") assert !Attachment.valid_extension?(".jpeg") end - with_settings :attachment_extensions_denied => "txt, Png" do + with_settings :attachment_extensions_denied => "txt\r\n Png" do assert !Attachment.valid_extension?(".pnG") assert Attachment.valid_extension?(".jpeg") end diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 524b37072..77558055f 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -33,6 +33,7 @@ class MailHandlerTest < ActiveSupport::TestCase FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler' def setup + set_tmp_attachments_directory ActionMailer::Base.deliveries.clear Setting.notified_events = Redmine::Notifiable.all.collect(&:name) User.current = nil @@ -546,7 +547,6 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_add_issue_from_apple_mail - set_tmp_attachments_directory issue = submit_email( 'apple_mail_with_attachment.eml', :issue => {:project => 'ecookbook'} @@ -563,7 +563,6 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_thunderbird_with_attachment_ja - set_tmp_attachments_directory issue = submit_email( 'thunderbird_with_attachment_ja.eml', :issue => {:project => 'ecookbook'} @@ -588,7 +587,6 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_gmail_with_attachment_ja - set_tmp_attachments_directory issue = submit_email( 'gmail_with_attachment_ja.eml', :issue => {:project => 'ecookbook'} @@ -604,7 +602,6 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_thunderbird_with_attachment_latin1 - set_tmp_attachments_directory issue = submit_email( 'thunderbird_with_attachment_iso-8859-1.eml', :issue => {:project => 'ecookbook'} @@ -623,7 +620,6 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_gmail_with_attachment_latin1 - set_tmp_attachments_directory issue = submit_email( 'gmail_with_attachment_iso-8859-1.eml', :issue => {:project => 'ecookbook'} @@ -642,7 +638,6 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_mail_with_attachment_latin2 - set_tmp_attachments_directory issue = submit_email( 'ticket_with_text_attachment_iso-8859-2.eml', :issue => {:project => 'ecookbook'} @@ -995,7 +990,6 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_reply_to_a_nonexistent_issue - set_tmp_attachments_directory Issue.find(2).destroy assert_no_difference 'Issue.count' do assert_no_difference 'Journal.count' do @@ -1157,7 +1151,7 @@ class MailHandlerTest < ActiveSupport::TestCase end def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored - with_settings :mail_handler_excluded_filenames => "*.vcf,\n *.jpg" do + with_settings :mail_handler_excluded_filenames => "*.vcf\r\n *.jpg" do issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'}) assert issue.is_a?(Issue) assert !issue.new_record?