diff options
author | Go MAEDA <maeda@farend.jp> | 2021-04-16 01:36:59 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-04-16 01:36:59 +0000 |
commit | e41cf61de80bb183abeae8c1674cb7d0ef9d1277 (patch) | |
tree | 7048ac258cd3c7990c8b541f72a3efd600807e94 /app/models/attachment.rb | |
parent | 2027b8750aa8f6432cf58fc5b0f8bf15ef8a03d8 (diff) | |
download | redmine-e41cf61de80bb183abeae8c1674cb7d0ef9d1277.tar.gz redmine-e41cf61de80bb183abeae8c1674cb7d0ef9d1277.zip |
Validate attachment filenames on every change (#34367).
Patch by Holger Just.
git-svn-id: http://svn.redmine.org/redmine/trunk@20946 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/attachment.rb')
-rw-r--r-- | app/models/attachment.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 241ed0d70..c3c3fc8b3 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -30,7 +30,8 @@ class Attachment < ActiveRecord::Base validates_length_of :filename, :maximum => 255 validates_length_of :disk_filename, :maximum => 255 validates_length_of :description, :maximum => 255 - validate :validate_max_file_size, :validate_file_extension + validate :validate_max_file_size + validate :validate_file_extension, :if => :filename_changed? acts_as_event( :title => :filename, @@ -103,11 +104,9 @@ class Attachment < ActiveRecord::Base end def validate_file_extension - if @temp_file - extension = File.extname(filename) - unless self.class.valid_extension?(extension) - errors.add(:base, l(:error_attachment_extension_not_allowed, :extension => extension)) - end + extension = File.extname(filename) + unless self.class.valid_extension?(extension) + errors.add(:base, l(:error_attachment_extension_not_allowed, :extension => extension)) end end |