Skip to content

Commit

Permalink
target_dependency: Fix crash if target_proxy is nil.
Browse files Browse the repository at this point in the history
If `target_proxy` is `nil`, calling `to_tree_hash` on it will raise an
exception: undefined method `to_tree_hash' for nil:NilClass
(NoMethodError).
  • Loading branch information
byohay committed Jul 16, 2023
1 parent 2ce68b6 commit 079bd2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/xcodeproj/project/object/target_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def to_tree_hash
hash = {}
hash['displayName'] = display_name
hash['isa'] = isa
hash['targetProxy'] = target_proxy.to_tree_hash
hash['targetProxy'] = target_proxy.to_tree_hash if target_proxy
hash
end

Expand Down
11 changes: 11 additions & 0 deletions spec/project/object/target_dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ module ProjectSpecs
}
end

it 'tree hash for target dependency without target proxy' do
target = @project.new_target(:static, 'Pods', :ios)
@target_dependency.target = target
target.dependencies << @target_dependency

@target_dependency.to_tree_hash.should == {
'displayName' => 'Pods',
'isa' => 'PBXTargetDependency',
}
end

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

describe '#display_name' do
Expand Down

0 comments on commit 079bd2f

Please sign in to comment.