Skip to content

Commit

Permalink
[Source] Fix a crash when searching for compatible versions
Browse files Browse the repository at this point in the history
Closes #482
  • Loading branch information
amorde committed Apr 14, 2019
1 parent 00c7f81 commit d5620a8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

##### Bug Fixes

* None.
* Fix a crash when searching for a compatible version of a Source that has a higher version requirement
[Eric Amorde](https://github.com/amorde)
[#482](https://github.com/CocoaPods/Core/issues/482)


## 1.7.0.beta.3 (2019-03-27)
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-core/source/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def path_fragment(pod_name, version = nil)
def last_compatible_version(target_version)
return unless minimum_cocoapods_version
return if minimum_cocoapods_version <= target_version
@last_compatible_versions.reverse_each.bsearch { |v| v <= target_version }.tap do |version|
Array(@last_compatible_versions.reverse_each).bsearch { |v| v <= target_version }.tap do |version|
raise Informative, 'Unable to find compatible version' unless version
end
end
Expand Down
24 changes: 24 additions & 0 deletions spec/source/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ module Pod
end
end

describe '#last_compatible_version' do
it 'returns the last compatible version if available' do
metadata_hash = {
'min' => '1.9.0',
'max' => '2.0.0',
'last_compatible_versions' => %w(1.0 1.4 2.0)
}
metadata = Source::Metadata.new(metadata_hash)
result = metadata.last_compatible_version(Version.new('1.5.0'))
result.should == Pod::Version.new('1.4.0')
end

it 'raises when unable to find a compatible version' do
metadata_hash = {
'min' => '2.0.0',
'max' => '2.0.0'
}
metadata = Source::Metadata.new(metadata_hash)
should.raise Pod::Informative do
metadata.last_compatible_version(Version.new('1.5.0'))
end.message.should.match /Unable to find compatible version/
end
end

describe '#compatible?' do
it 'returns whether a repository is compatible' do
@metadata = Source::Metadata.new('min' => '0.0.1')
Expand Down

0 comments on commit d5620a8

Please sign in to comment.