public
Description: Paperclip File Management Plugin
Homepage: http://www.thoughtbot.com/projects/paperclip
Clone URL: git://github.com/thoughtbot/paperclip.git
added sanitizing of filenames
iffy (author)
Mon Jun 09 02:50:32 -0700 2008
commit  14fb769806084f77b23e795e82867694b158d5a0
tree    c06f2a35c715865229306c6391a8f1aae7947f80
parent  edfff2fb48efd52ca0430c932deb293f3f53befe
...
58
59
60
61
 
62
63
64
...
58
59
60
 
61
62
63
64
0
@@ -58,7 +58,7 @@ module Paperclip
0
       return nil if uploaded_file.nil?
0
 
0
       @queued_for_write[:original] = uploaded_file.to_tempfile
0
- @instance[:"#{@name}_file_name"] = uploaded_file.original_filename.strip
0
+ @instance[:"#{@name}_file_name"] = uploaded_file.original_filename.strip.gsub /[^A-Za-z0-9\.]/, '_'
0
       @instance[:"#{@name}_content_type"] = uploaded_file.content_type.strip
0
       @instance[:"#{@name}_file_size"] = uploaded_file.size.to_i
0
 
...
113
114
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
117
118
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
0
@@ -113,6 +113,33 @@ class AttachmentTest < Test::Unit::TestCase
0
     should "strip whitespace from content_type field" do
0
       assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
0
     end
0
+
0
+ end
0
+
0
+ context "Attachment with strange letters" do
0
+ setup do
0
+ rebuild_model
0
+
0
+ @not_file = mock
0
+ @not_file.stubs(:nil?).returns(false)
0
+ @not_file.expects(:to_tempfile).returns(self)
0
+ @not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n")
0
+ @not_file.expects(:content_type).returns("image/png\r\n")
0
+ @not_file.expects(:size).returns(10)
0
+
0
+ @dummy = Dummy.new
0
+ @attachment = @dummy.avatar
0
+ @attachment.expects(:valid_assignment?).with(@not_file).returns(true)
0
+ @attachment.expects(:queue_existing_for_delete)
0
+ @attachment.expects(:post_process)
0
+ @attachment.expects(:validate)
0
+ @dummy.avatar = @not_file
0
+ end
0
+
0
+ should "remove strange letters and replace with underscore (_)" do
0
+ assert_equal "sheep_say_b__.png", @dummy.avatar.original_filename
0
+ end
0
+
0
   end
0
 
0
   context "An attachment" do

Comments

    No one has commented yet.