Commit a6c86832 by Prem Sichanugrist

Handle the case when :restricted_characters is nil

Fixes #762
parent 3a3c2277
......@@ -441,6 +441,8 @@ module Paperclip
def cleanup_filename(filename)
if @options[:restricted_characters]
filename.gsub(@options[:restricted_characters], '_')
else
filename
end
end
end
......
......@@ -768,6 +768,14 @@ class AttachmentTest < Test::Unit::TestCase
context "with specified regexp replacement" do
setup do
@old_defaults = Paperclip::Attachment.default_options.dup
end
teardown do
Paperclip::Attachment.default_options.merge! @old_defaults
end
context 'as another regexp' do
setup do
Paperclip::Attachment.default_options.merge! :restricted_characters => /o/
@file.stubs(:original_filename).returns("goood.png")
......@@ -775,14 +783,25 @@ class AttachmentTest < Test::Unit::TestCase
@dummy.avatar = @file
end
teardown do
Paperclip::Attachment.default_options.merge! @old_defaults
end
should "match and convert that character" do
assert_equal "g___d.png", @dummy.avatar.original_filename
end
end
context 'as nil' do
setup do
Paperclip::Attachment.default_options.merge! :restricted_characters => nil
@file.stubs(:original_filename).returns("goood.png")
@dummy = Dummy.new
@dummy.avatar = @file
end
should "ignore and return the original file name" do
assert_equal "goood.png", @dummy.avatar.original_filename
end
end
end
end
context "Attachment with uppercase extension and a default style" do
......
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