Skip to content

Commit

Permalink
Merge pull request #742 from sagiwei/fix_subspec_by_name
Browse files Browse the repository at this point in the history
Fix crash when retrieve subspec from a unavailable podspec file
  • Loading branch information
amorde committed Dec 24, 2023
2 parents 34a3df0 + f13b963 commit d756e4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
[fnxpt](https://github.com/fnxpt)
[#748](https://github.com/CocoaPods/Core/issues/748)

* Fix a crash when calling Specification#subspec_by_name on a deprecated specification with no name
[sagiwei](https://github.com/sagiwei)
[#742](https://github.com/CocoaPods/Core/pull/742)


## 1.14.3 (2023-11-19)

Expand Down
7 changes: 7 additions & 0 deletions lib/cocoapods-core/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ def recursive_subspecs
def subspec_by_name(relative_name, raise_if_missing = true, include_non_library_specifications = false)
if relative_name.nil? || relative_name == base_name
self
elsif base_name.nil?
if raise_if_missing
raise Informative, "Trying to access a `#{relative_name}` " \
"specification from `#{defined_in_file}`, which has no contents."
else
return nil
end
elsif relative_name.downcase == base_name.downcase
raise Informative, "Trying to access a `#{relative_name}` " \
"specification from `#{base_name}`, which has a different case."
Expand Down
9 changes: 9 additions & 0 deletions spec/specification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,15 @@ module Pod
@spec.subspec_by_name('Pod/Subspec/Subsubspec/Missing', false).should.be.nil?
end

describe 'deprecated podspec' do
it 'returns nil for an empty deprecated spec' do
@spec = Spec.new do |s|
s.deprecated_in_favor_of = 'SomeOtherSpec'
end
@spec.subspec_by_name('subspec', false).should.be.nil?
end
end

it 'returns the default subspecs' do
spec = @spec.dup
spec.default_subspecs = 'Subspec1', 'Subspec2'
Expand Down

0 comments on commit d756e4c

Please sign in to comment.