Browse Source

Fixed: wrong digest for text files under Windows (#2264).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2085 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/0.8.0-RC1
Jean-Philippe Lang 15 years ago
parent
commit
93c04f2666
3 changed files with 16 additions and 3 deletions
  1. 8
    1
      app/models/attachment.rb
  2. 2
    1
      test/fixtures/files/testfile.txt
  3. 6
    1
      test/unit/attachment_test.rb

+ 8
- 1
app/models/attachment.rb View File

File.open(diskfile, "wb") do |f| File.open(diskfile, "wb") do |f|
f.write(@temp_file.read) f.write(@temp_file.read)
end end
self.digest = Digest::MD5.hexdigest(File.read(diskfile))
self.digest = self.class.digest(diskfile)
end end
# Don't save the content type if it's longer than the authorized length # Don't save the content type if it's longer than the authorized length
if self.content_type && self.content_type.length > 255 if self.content_type && self.content_type.length > 255
end end
df df
end end
# Returns the MD5 digest of the file at given path
def self.digest(filename)
File.open(filename, 'rb') do |f|
Digest::MD5.hexdigest(f.read)
end
end
end end

+ 2
- 1
test/fixtures/files/testfile.txt View File

this is a text file for upload tests
this is a text file for upload tests
with multiple lines

+ 6
- 1
test/unit/attachment_test.rb View File

require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'


class AttachmentTest < Test::Unit::TestCase class AttachmentTest < Test::Unit::TestCase

fixtures :issues, :users
def setup def setup
end end
assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1] assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1]
assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1] assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
end end
def test_digest
assert_equal '1478adae0d4eb06d35897518540e25d6', Attachment.digest(Test::Unit::TestCase.fixture_path + "/files/testfile.txt")
end
end end

Loading…
Cancel
Save