From 434f30fe42af9b78bc769b748ddde5321d37bd07 Mon Sep 17 00:00:00 2001 From: Austin Date: Thu, 11 Apr 2013 08:44:16 -0700 Subject: [PATCH 1/4] added support for directories with single quotes. fixes #315 --- lib/foreman/process.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 2abcb82..2424c11 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -47,7 +47,8 @@ class Foreman::Process def run(options={}) env = @options[:env].merge(options[:env] || {}) output = options[:output] || $stdout - + runner = "#{Foreman.runner}".gsub("'", "\\\\'") # To support directories with single quotes + cwd = "#{cwd}".gsub("'", "\\\\'") if Foreman.windows? Dir.chdir(cwd) do Process.spawn env, expanded_command(env), :out => output, :err => output From ad4d59ae140f38d18d69a394cd07edaa456bd81b Mon Sep 17 00:00:00 2001 From: Austin Date: Thu, 11 Apr 2013 08:49:36 -0700 Subject: [PATCH 2/4] fixes #315 --- lib/foreman/process.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 2424c11..446989b 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -48,25 +48,25 @@ class Foreman::Process env = @options[:env].merge(options[:env] || {}) output = options[:output] || $stdout runner = "#{Foreman.runner}".gsub("'", "\\\\'") # To support directories with single quotes - cwd = "#{cwd}".gsub("'", "\\\\'") + cwdstr = "#{cwd}".gsub("'", "\\\\'") if Foreman.windows? Dir.chdir(cwd) do Process.spawn env, expanded_command(env), :out => output, :err => output end elsif Foreman.jruby_18? require "posix/spawn" - wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}" + wrapped_command = "#{runner} -d '#{cwdstr}' -p -- #{command}" POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output elsif Foreman.ruby_18? fork do $stdout.reopen output $stderr.reopen output env.each { |k,v| ENV[k] = v } - wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}" + wrapped_command = "#{runner} -d '#{cwdstr}' -p -- #{command}" Kernel.exec wrapped_command end else - wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}" + wrapped_command = "#{Foreman.runner} -d '#{cwdstr}' -p -- #{command}" Process.spawn env, wrapped_command, :out => output, :err => output end end From 6611d818b1a9d8a7ca77a0446cd459fca37f5941 Mon Sep 17 00:00:00 2001 From: Austin Date: Thu, 11 Apr 2013 09:14:01 -0700 Subject: [PATCH 3/4] third time is the charm. :) --- lib/foreman/process.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 446989b..a470d7e 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -47,26 +47,24 @@ class Foreman::Process def run(options={}) env = @options[:env].merge(options[:env] || {}) output = options[:output] || $stdout - runner = "#{Foreman.runner}".gsub("'", "\\\\'") # To support directories with single quotes - cwdstr = "#{cwd}".gsub("'", "\\\\'") if Foreman.windows? Dir.chdir(cwd) do Process.spawn env, expanded_command(env), :out => output, :err => output end elsif Foreman.jruby_18? require "posix/spawn" - wrapped_command = "#{runner} -d '#{cwdstr}' -p -- #{command}" + wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output elsif Foreman.ruby_18? fork do $stdout.reopen output $stderr.reopen output env.each { |k,v| ENV[k] = v } - wrapped_command = "#{runner} -d '#{cwdstr}' -p -- #{command}" + wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") Kernel.exec wrapped_command end else - wrapped_command = "#{Foreman.runner} -d '#{cwdstr}' -p -- #{command}" + wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") Process.spawn env, wrapped_command, :out => output, :err => output end end From e79588fd40ab5175c7533179ece730677854bdab Mon Sep 17 00:00:00 2001 From: Austin Date: Mon, 15 Apr 2013 08:01:24 -0700 Subject: [PATCH 4/4] modified to use shellescape instead of gsub --- lib/foreman/process.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index a470d7e..2cd808f 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -1,4 +1,5 @@ require "foreman" +require "shellwords" class Foreman::Process @@ -47,24 +48,25 @@ class Foreman::Process def run(options={}) env = @options[:env].merge(options[:env] || {}) output = options[:output] || $stdout + runner = "#{Foreman.runner}".shellescape if Foreman.windows? Dir.chdir(cwd) do Process.spawn env, expanded_command(env), :out => output, :err => output end elsif Foreman.jruby_18? require "posix/spawn" - wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") + wrapped_command = "#{runner} -d #{cwd.shellescape} -p -- #{command}" POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output elsif Foreman.ruby_18? fork do $stdout.reopen output $stderr.reopen output env.each { |k,v| ENV[k] = v } - wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") + wrapped_command = "#{runner} -d #{cwd.shellescape} -p -- #{command}" Kernel.exec wrapped_command end else - wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") + wrapped_command = "#{runner} -d #{cwd.shellescape} -p -- #{command}" Process.spawn env, wrapped_command, :out => output, :err => output end end