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
3e98fc2e
Commit
3e98fc2e
authored
Apr 15, 2012
by
Kir Maximov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a problem with incorrect content_type detected with 'file' command for an empty file on Mac
parent
05a23718
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletions
+8
-1
lib/paperclip/io_adapters/file_adapter.rb
+1
-1
test/file_adapter_test.rb
+7
-0
No files found.
lib/paperclip/io_adapters/file_adapter.rb
View file @
3e98fc2e
...
...
@@ -69,7 +69,7 @@ module Paperclip
def
type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type
=
(
self
.
original_filename
.
match
(
/\.(\w+)$/
)[
1
]
rescue
"octet-stream"
).
downcase
mime_type
=
(
Paperclip
.
run
(
"file"
,
"-b --mime :file"
,
:file
=>
self
.
path
).
split
(
/[:;
]\s
+/
)[
0
]
rescue
"application/x-
#{
type
}
"
)
mime_type
=
(
Paperclip
.
run
(
"file"
,
"-b --mime :file"
,
:file
=>
self
.
path
).
split
(
/[:;
\s]
+/
)[
0
]
rescue
"application/x-
#{
type
}
"
)
mime_type
=
"application/x-
#{
type
}
"
if
mime_type
.
match
(
/\(.*?\)/
)
mime_type
end
...
...
test/file_adapter_test.rb
View file @
3e98fc2e
...
...
@@ -20,6 +20,13 @@ class FileAdapterTest < Test::Unit::TestCase
assert_equal
"image/png"
,
@subject
.
content_type
end
should
"provide correct mime-type for empty file"
do
@subject
=
Paperclip
.
io_adapters
.
for
(
Tempfile
.
new
(
"file_adapter_test"
))
# Content type contained '\n' at the end, for an empty file, on my Mac
assert_equal
"application/x-empty"
,
@subject
.
content_type
end
should
"get the file's size"
do
assert_equal
4456
,
@subject
.
size
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