Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
83d8ec5a
Commit
83d8ec5a
authored
Oct 19, 2012
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Translate bad filename characters
parent
86dc49bd
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
3 deletions
+19
-3
lib/paperclip/io_adapters/abstract_adapter.rb
+6
-0
lib/paperclip/io_adapters/stringio_adapter.rb
+2
-1
lib/paperclip/io_adapters/uri_adapter.rb
+2
-1
test/helper.rb
+1
-0
test/io_adapters/abstract_adapter_test.rb
+8
-1
No files found.
lib/paperclip/io_adapters/abstract_adapter.rb
View file @
83d8ec5a
...
...
@@ -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
...
...
lib/paperclip/io_adapters/stringio_adapter.rb
View file @
83d8ec5a
...
...
@@ -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
...
...
lib/paperclip/io_adapters/uri_adapter.rb
View file @
83d8ec5a
...
...
@@ -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
...
...
test/helper.rb
View file @
83d8ec5a
...
...
@@ -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
}
"
...
...
test/io_adapters/abstract_adapter_test.rb
View file @
83d8ec5a
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment