Project

General

Profile

Patch #24186 ยป 0001-Shorten-long-attachment-disk-filenames.patch

Holger Just, 2016-10-27 17:18

View differences:

app/models/attachment.rb
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)
test/unit/attachment_test.rb
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
    (1-1/1)