Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All download handlers support target paths with quotes #6

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/cocoapods-downloader/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def name
self.class.name.split('::').last
end

def escaped_target_path
escape_pathname(target_path)
end

#-----------------------------------------------------------------------#

# @!group Configuration
Expand Down Expand Up @@ -224,6 +228,11 @@ def self.executable(name)
execute_command(name.to_s, command, true)
end
end

def escape_pathname(pathname=target_path)
escaped_string = pathname.to_s.gsub "\"", "\\\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace this by using String#shellescape instead please?

http://apidock.com/ruby/v1_8_7_72/Shellwords/shellescape

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. When I was working on this earlier, I was seeing unexpected behavior using shellescape (hence this jankiness) but trying it again now it seems to work. New commit incoming — thanks for the suggestion!

Pathname.new(escaped_string)
end
end
end
end
4 changes: 2 additions & 2 deletions lib/cocoapods-downloader/bazaar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def download!
end

def download_head!
bzr! %|branch "#{url}" #{dir_opts} "#{target_path}"|
bzr! %|branch "#{url}" #{dir_opts} "#{escaped_target_path}"|
end

def download_revision!(rev)
bzr! %|branch "#{url}" #{dir_opts} -r '#{rev}' "#{target_path}"|
bzr! %|branch "#{url}" #{dir_opts} -r '#{rev}' "#{escaped_target_path}"|
end

def dir_opts
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-downloader/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def clone_url
#
def clone(from, to, flags = '')
ui_sub_action("Cloning to Pods folder") do
command = %Q|clone "#{from}" "#{to}"|
command = %Q|clone "#{from}" "#{escape_pathname(to)}"|
command << ' ' + flags if flags
git!(command)
end
Expand Down
14 changes: 7 additions & 7 deletions lib/cocoapods-downloader/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UnsupportedFileTypeError < StandardError; end

def download!
@filename = filename_with_type(type)
@download_path = target_path + @filename
@download_path = escape_pathname(target_path + @filename)
download_file(@download_path)
extract_with_type(@download_path, type)
end
Expand Down Expand Up @@ -84,21 +84,21 @@ def filename_with_type(type=:zip)
end

def download_file(full_filename)
curl! "-L -o '#{full_filename}' '#{url}'"
curl! %|-L -o "#{full_filename}" "#{url}" --create-dirs|
end

def extract_with_type(full_filename, type=:zip)
case type
when :zip
unzip! "'#{full_filename}' -d '#{target_path}'"
unzip! %|"#{full_filename}" -d "#{escaped_target_path}"|
when :tgz
tar! "xfz '#{full_filename}' -C '#{target_path}'"
tar! %|xfz "#{full_filename}" -C "#{escaped_target_path}"|
when :tar
tar! "xf '#{full_filename}' -C '#{target_path}'"
tar! %|xf "#{full_filename}" -C "#{escaped_target_path}"|
when :tbz
tar! "xfj '#{full_filename}' -C '#{target_path}'"
tar! %|xfj "#{full_filename}" -C "#{escaped_target_path}"|
when :txz
tar! "xf '#{full_filename}' -C '#{target_path}'"
tar! %|xf "#{full_filename}" -C "#{escaped_target_path}"|
else
raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/cocoapods-downloader/mercurial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def download!
end

def download_head!
hg! %|clone "#{url}" "#{target_path}"|
hg! %|clone "#{url}" "#{escaped_target_path}"|
end

def download_revision!
hg! %|clone "#{url}" --rev '#{options[:revision]}' "#{target_path}"|
hg! %|clone "#{url}" --rev '#{options[:revision]}' "#{escaped_target_path}"|
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/cocoapods-downloader/subversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def checkout_options
executable :svn

def download!
output = svn!(%|#{export_subcommand} "#{reference_url}" "#{target_path}"|)
output = svn!(%|#{export_subcommand} "#{reference_url}" "#{escaped_target_path}"|)
store_exported_revision(output)
end

def download_head!
output = svn!(%|#{export_subcommand} "#{trunk_url}" "#{target_path}"|)
output = svn!(%|#{export_subcommand} "#{trunk_url}" "#{escaped_target_path}"|)
store_exported_revision(output)
end

Expand Down
16 changes: 16 additions & 0 deletions spec/cocoapods-downloaders/bazaar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ module Downloader
tmp_folder('README').read.strip.should == 'Fourth Commit'
end

describe "when the directory name has quotes or spaces" do
it 'checks out the head revision' do
options = { :bzr => fixture('bazaar-repo') }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes("README").read.strip.should == 'Fourth Commit'
end

it 'checks out a specific revision into a directory with quotes' do
options = { :bzr => fixture('bazaar-repo'), :revision => '1' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes("README").read.strip.should == 'First Commit'
end
end

it 'returns the checked out revision' do
options = { :bzr => fixture('bazaar-repo') }
downloader = Downloader.for_target(tmp_folder, options)
Expand Down
8 changes: 8 additions & 0 deletions spec/cocoapods-downloaders/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ module Downloader
tmp_folder('README').read.strip.should == 'first commit'
end


it "checks out when the path contains quotes or spaces" do
options = { :git => fixture('git-repo'), :commit => '7ad3a6c' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes("README").read.strip.should == 'first commit'
end

it "checks out a specific branch" do
options = { :git => fixture('git-repo'), :branch => 'topic_branch' }
downloader = Downloader.for_target(tmp_folder, options)
Expand Down
8 changes: 8 additions & 0 deletions spec/cocoapods-downloaders/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ module Downloader
tmp_folder('GoogleAdMobSearchAdsSDK/GADSearchRequest.h').read.strip.should =~ /Google Search Ads iOS SDK/
end

it 'should download file and unzip it when the target folder name contains quotes or spaces' do
options = { :http => 'http://dl.google.com/googleadmobadssdk/googleadmobsearchadssdkios.zip' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
tmp_folder_with_quotes("GoogleAdMobSearchAdsSDK/GADSearchRequest.h").should.exist
tmp_folder_with_quotes("GoogleAdMobSearchAdsSDK/GADSearchRequest.h").read.strip.should =~ /Google Search Ads iOS SDK/
end

it 'should flatten zip archives, when the spec explicitly demands it' do
options = {
:http => 'https://github.com/kevinoneill/Useful-Bits/archive/1.0.zip',
Expand Down
16 changes: 16 additions & 0 deletions spec/cocoapods-downloaders/mercurial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ module Downloader
tmp_folder('README').read.strip.should == 'second commit'
end

describe "when the directory name has quotes or spaces" do
it "checks out a specific revision" do
options = { :hg => fixture('mercurial-repo'), :revision => '46198bb3af96' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'first commit'
end

it "checks out the head revision" do
options = { :hg => fixture('mercurial-repo') }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'second commit'
end
end

it "returns the checked out revision" do
options = { :hg => fixture('mercurial-repo') }
downloader = Downloader.for_target(tmp_folder, options)
Expand Down
16 changes: 16 additions & 0 deletions spec/cocoapods-downloaders/subversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ module Downloader
tmp_folder('README').read.strip.should == 'unintersting'
end

describe "when the directory name has quotes or spaces" do
it "checks out a specific revision" do
options = { :svn => "file://#{fixture('subversion-repo')}", :revision => '1' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'first commit'
end

it "checks out the head version" do
options = { :svn => "file://#{fixture('subversion-repo')}", :tag => 'tag-1' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download_head
tmp_folder_with_quotes('README').read.strip.should == 'unintersting'
end
end

it "returns the checked out revision" do
options = { :svn => "file://#{fixture('subversion-repo')}" }
downloader = Downloader.for_target(tmp_folder, options)
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def tmp_folder(path = '')
return Pathname.pwd + 'tmp' + path
end

def tmp_folder_with_quotes(path = '')
return tmp_folder File.join("a' \"b", path)
end

def fixture(path)
return Pathname.pwd + 'spec/fixtures/' + path
end
Expand Down