##// END OF EJS Templates
Restrict the length attachment filenames on disk (#24186)....
Jean-Philippe Lang -
r15701:20be00e437a5
parent child
Show More
@@ -413,7 +413,7 class Attachment < ActiveRecord::Base
413 413 def self.disk_filename(filename, directory=nil)
414 414 timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
415 415 ascii = ''
416 if filename =~ %r{^[a-zA-Z0-9_\.\-]*$}
416 if filename =~ %r{^[a-zA-Z0-9_\.\-]*$} && filename.length <= 50
417 417 ascii = filename
418 418 else
419 419 ascii = Digest::MD5.hexdigest(filename)
@@ -81,6 +81,19 class AttachmentTest < ActiveSupport::TestCase
81 81 assert_nil a.content_type
82 82 end
83 83
84 def test_shorted_filename_if_too_long
85 file = uploaded_test_file("testfile.txt", "text/plain")
86 file.instance_variable_set('@original_filename', "#{'a'*251}.txt")
87 assert 255, file.original_filename.length
88
89 a = Attachment.new(:container => Issue.find(1),
90 :file => file,
91 :author => User.find(1))
92 assert a.save
93 a.reload
94 assert_equal 12 + 1 + 32 + 4, a.disk_filename.length
95 end
96
84 97 def test_copy_should_preserve_attributes
85 98 a = Attachment.find(1)
86 99 copy = a.copy
General Comments 0
You need to be logged in to leave comments. Login now