Commit a6c86832 by Prem Sichanugrist

Handle the case when :restricted_characters is nil

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