Commit 3a8cbe64 authored by Olivier Halligon's avatar Olivier Halligon Committed by Olivier Halligon

Fix for CocoaPods/Core#188

parent 3cbfa114
......@@ -15,6 +15,7 @@ module Pod
def self.options
[
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--full', 'Search by name, summary, and description'],
['--stats', 'Show additional stats (like GitHub watchers and forks)'],
['--ios', 'Restricts the search to Pods supported on iOS'],
......@@ -24,6 +25,7 @@ module Pod
end
def initialize(argv)
@use_regex = argv.flag?('regex')
@full_text_search = argv.flag?('full')
@stats = argv.flag?('stats')
@supported_on_ios = argv.flag?('ios')
......@@ -38,7 +40,7 @@ module Pod
super
help! 'A search query is required.' unless @query
unless @web
unless @web || !@use_regex
begin
/#{@query.join(' ').strip}/
rescue RegexpError
......@@ -71,7 +73,10 @@ module Pod
end
def local_search
sets = SourcesManager.search_by_name(@query.join(' ').strip, @full_text_search)
query_regex = @query.join(' ').strip
query_regex = Regexp.escape(query_regex) unless @use_regex
sets = SourcesManager.search_by_name(query_regex, @full_text_search)
if @supported_on_ios
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
end
......
......@@ -337,7 +337,7 @@ module Pod
# @return [Pathname] the absolute path or paths of the given podspec
#
def get_path_of_spec(spec, show_all = false)
sets = SourcesManager.search_by_name(spec)
sets = SourcesManager.search_by_name(Regexp.escape(spec))
if sets.count == 1
set = sets.first
......
Pod::Spec.new do |s|
s.name = 'Foo+Bar'
s.version = '1.0'
s.authors = 'FooBar Corp'
s.homepage = 'http://foobar-corp.local/foobar.html'
s.summary = 'Wohoo foobars!'
s.description = 'Silly foos, silly bars.'
s.platform = :ios
s.source = { :git => 'http://foobar-corp.local/foobar.git', :tag => '1.0' }
s.source_files = 'Classes/*.{h,m}'
s.license = {
:type => 'MIT',
:file => 'LICENSE',
:text => 'Permission is hereby granted ...'
}
end
......@@ -22,11 +22,14 @@ module Pod
jsonkit_set = sets.find { |s| s.name == 'JSONKit' }
dates = {
'BananaLib' => Time.now,
'JSONKit' => Time.parse('01/01/1970') }
'JSONKit' => Time.parse('01/01/1970'),
'Foo+Bar' => Time.parse('01/01/1970'),
}
Specification::Set::Statistics.any_instance.stubs(:creation_dates).returns(dates)
out = run_command('list', 'new')
out.should.include('BananaLib')
out.should.not.include('JSONKit')
out.should.not.include('Foo+Bar')
end
it 'presents the known pods with versions' do
......
......@@ -51,7 +51,18 @@ module Pod
end
it 'shows a friendly message when locally searching with invalid regex' do
lambda { run_command('search', '+') }.should.raise CLAide::Help
lambda { run_command('search', '--regex', '+') }.should.raise CLAide::Help
end
it 'uses regex when asked for regex mode' do
output = run_command('search', '--regex', 'Ba(na)+Lib')
output.should.include? 'BananaLib'
end
it 'uses plain-text search when not asked for regex mode' do
output = run_command('search', 'Foo+Bar')
output.should.include? 'Foo+Bar'
output.should.not.include? 'BananaLib'
end
describe 'option --web' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment