Project

General

Profile

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

Go MAEDA, 2020-04-25 10:27

View differences:

app/models/attachment.rb
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)
app/models/mail_handler.rb
# 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
test/unit/attachment_test.rb
end
def test_extension_should_be_validated_against_denied_extensions
with_settings :attachment_extensions_denied => "txt, png" do
with_settings :attachment_extensions_denied => "txt, png\r\ncsv" do
a = Attachment.new(:container => Issue.find(1),
:file => mock_file_with_options(:original_filename => "test.jpeg"),
:author => User.find(1))
......
end
def test_valid_extension_should_be_case_insensitive
with_settings :attachment_extensions_allowed => "txt, Png" do
with_settings :attachment_extensions_allowed => "txt, Png\r\ncsv" 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, Png\r\ncsv" do
assert !Attachment.valid_extension?(".pnG")
assert Attachment.valid_extension?(".jpeg")
end
test/unit/mail_handler_test.rb
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,\n *.jpg\r\n*.csv" do
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
assert issue.is_a?(Issue)
assert !issue.new_record?
......
end
def test_attachments_that_match_mail_handler_excluded_filenames_by_regex_should_be_ignored
with_settings :mail_handler_excluded_filenames => '.+\.vcf,(pa|nut)ella\.jpg',
with_settings :mail_handler_excluded_filenames => ".+\\.vcf,(pa|nut)ella\\.jpg\r\n.+\\.csv",
:mail_handler_enable_regex_excluded_filenames => 1 do
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
assert issue.is_a?(Issue)
(3-3/3)