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
00c0daf4
Commit
00c0daf4
authored
Aug 05, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use single-quote to quote windows command lines.
parent
ba697508
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
lib/paperclip/command_line.rb
+9
-2
test/command_line_test.rb
+29
-0
No files found.
lib/paperclip/command_line.rb
View file @
00c0daf4
...
...
@@ -62,12 +62,19 @@ module Paperclip
def
shell_quote
(
string
)
return
""
if
string
.
nil?
or
string
.
blank?
if
self
.
class
.
unix?
string
.
split
(
"'"
).
map
{
|
m
|
"'
#{
m
}
'"
}.
join
(
"
\\
'"
)
else
%{"#{string}"}
end
end
def
bit_bucket
return
"2>NUL"
unless
File
.
exist?
(
"/dev/null"
)
"2>/dev/null"
self
.
class
.
unix?
?
"2>/dev/null"
:
"2>NUL"
end
def
self
.
unix?
File
.
exist?
(
"/dev/null"
)
end
end
end
test/command_line_test.rb
View file @
00c0daf4
...
...
@@ -3,6 +3,7 @@ require 'test/helper'
class
CommandLineTest
<
Test
::
Unit
::
TestCase
def
setup
Paperclip
::
CommandLine
.
path
=
nil
File
.
stubs
(
:exist?
).
with
(
"/dev/null"
).
returns
(
true
)
end
should
"take a command and parameters and produce a shell command for bash"
do
...
...
@@ -24,6 +25,15 @@ class CommandLineTest < Test::Unit::TestCase
assert_equal
"convert 'a.jpg' 'b.png'"
,
cmd
.
command
end
should
"quote command line options differently if we're on windows"
do
File
.
stubs
(
:exist?
).
with
(
"/dev/null"
).
returns
(
false
)
cmd
=
Paperclip
::
CommandLine
.
new
(
"convert"
,
":one :{two}"
,
:one
=>
"a.jpg"
,
:two
=>
"b.png"
)
assert_equal
'convert "a.jpg" "b.png"'
,
cmd
.
command
end
should
"be able to quote and interpolate dangerous variables"
do
cmd
=
Paperclip
::
CommandLine
.
new
(
"convert"
,
":one :two"
,
...
...
@@ -32,6 +42,15 @@ class CommandLineTest < Test::Unit::TestCase
assert_equal
"convert '`rm -rf`.jpg' 'ha'
\\
''ha.png'"
,
cmd
.
command
end
should
"be able to quote and interpolate dangerous variables even on windows"
do
File
.
stubs
(
:exist?
).
with
(
"/dev/null"
).
returns
(
false
)
cmd
=
Paperclip
::
CommandLine
.
new
(
"convert"
,
":one :two"
,
:one
=>
"`rm -rf`.jpg"
,
:two
=>
"ha'ha.png"
)
assert_equal
%{convert "`rm -rf`.jpg" "ha'ha.png"}
,
cmd
.
command
end
should
"add redirection to get rid of stderr in bash"
do
File
.
stubs
(
:exist?
).
with
(
"/dev/null"
).
returns
(
true
)
cmd
=
Paperclip
::
CommandLine
.
new
(
"convert"
,
...
...
@@ -96,4 +115,14 @@ class CommandLineTest < Test::Unit::TestCase
Paperclip
.
expects
(
:log
).
with
(
"convert a.jpg b.png"
)
cmd
.
run
end
should
"detect that the system is unix or windows based on presence of /dev/null"
do
File
.
stubs
(
:exist?
).
returns
(
true
)
assert
Paperclip
::
CommandLine
.
unix?
end
should
"detect that the system is not unix or windows based on absence of /dev/null"
do
File
.
stubs
(
:exist?
).
returns
(
false
)
assert
!
Paperclip
::
CommandLine
.
unix?
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