Commit 0f4029c1 by Dan Dockery Committed by Jon Yurek

Use hexdigest to ensure that tempfile names will be a reasonable length. Remove…

Use hexdigest to ensure that tempfile names will be a reasonable length.  Remove illegal filename characters check since it is no longer relevant when doing a hexdigest on the filename
parent bfaec7c5
module Paperclip module Paperclip
class TempfileFactory class TempfileFactory
ILLEGAL_FILENAME_CHARACTERS = /\A~/
def generate(name) def generate(name)
@name = name @name = name
file = Tempfile.new([basename, extension]) file = Tempfile.new([basename, extension])
...@@ -15,7 +13,7 @@ module Paperclip ...@@ -15,7 +13,7 @@ module Paperclip
end end
def basename def basename
File.basename(@name, extension).gsub(ILLEGAL_FILENAME_CHARACTERS, '_') Digest::MD5.hexdigest(File.basename(@name, extension))
end end
end end
end end
...@@ -10,4 +10,8 @@ class Paperclip::TempfileFactoryTest < Test::Unit::TestCase ...@@ -10,4 +10,8 @@ class Paperclip::TempfileFactoryTest < Test::Unit::TestCase
should "be able to generate a tempfile with the right name with a tilde at the end" do should "be able to generate a tempfile with the right name with a tilde at the end" do
file = subject.generate("omg.png~") file = subject.generate("omg.png~")
end end
should "be able to generate a tempfile from a file with a really long name" do
filename = "#{"longfilename" * 100}.txt"
file = subject.generate(filename)
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment