Commit 83d8ec5a by Jon Yurek

Translate bad filename characters

parent 86dc49bd
......@@ -2,6 +2,8 @@ require 'active_support/core_ext/module/delegation'
module Paperclip
class AbstractAdapter
OS_RESTRICTED_CHARACTERS = %r{[/:]}
attr_reader :content_type, :original_filename, :size
delegate :close, :closed?, :eof?, :path, :rewind, :unlink, :to => :@tempfile
......@@ -17,6 +19,10 @@ module Paperclip
"#{self.class}: #{self.original_filename}"
end
def original_filename=(new_filename)
@original_filename = new_filename.gsub(OS_RESTRICTED_CHARACTERS, "_")
end
private
def destination
......
......@@ -6,7 +6,8 @@ module Paperclip
@tempfile = copy_to_tempfile(@target)
end
attr_writer :original_filename, :content_type
attr_writer :content_type
private
def cache_current_values
......
......@@ -9,7 +9,8 @@ module Paperclip
@tempfile = copy_to_tempfile(@content)
end
attr_writer :original_filename, :content_type
attr_writer :content_type
private
def download_content
......
......@@ -14,6 +14,7 @@ require 'active_support/core_ext'
require 'mime/types'
require 'pathname'
require 'ostruct'
require 'pry'
puts "Testing against version #{ActiveRecord::VERSION::STRING}"
......
......@@ -2,7 +2,7 @@ require './test/helper'
class AbstractAdapterTest < Test::Unit::TestCase
class TestAdapter < Paperclip::AbstractAdapter
attr_accessor :original_file_name, :tempfile
attr_accessor :tempfile
def content_type
Paperclip::ContentTypeDetector.new(path).detect
......@@ -40,4 +40,11 @@ class AbstractAdapterTest < Test::Unit::TestCase
end
end
end
should 'get rid of slashes and colons in filenames' do
@adapter = TestAdapter.new
@adapter.original_filename = "awesome/file:name.png"
assert_equal "awesome_file_name.png", @adapter.original_filename
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