Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

##### Bug Fixes

* None.
* Standardize podspec JSON serialization to Ruby 2.7+ behavior. This may result in checksum changes for
projects using Ruby 2.6 (macOS System Ruby).
[Eric Amorde](https://github.com/amorde)
[#787](https://github.com/CocoaPods/Core/pull/787)


## 1.17.0 (2026-07-06)
Expand Down
7 changes: 6 additions & 1 deletion lib/cocoapods-core/specification/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def to_json(*a)
#
def to_pretty_json(*a)
require 'json'
JSON.pretty_generate(to_hash, *a) << "\n"
json = JSON.pretty_generate(to_hash, *a)
# json < 2.8 (the newest available on Ruby < 2.7) renders empty arrays
# as "[\n\n ]" and empty hashes as "{\n }", while newer versions render
# "[]" and "{}". Normalize to the compact form so the output, and the
# checksums derived from it, don't depend on the Ruby/json version.
json.gsub(/": \[\n\n\s*\]/, '": []').gsub(/": \{\n\s*\}/, '": {}') << "\n"
end

#-----------------------------------------------------------------------#
Expand Down
17 changes: 12 additions & 5 deletions spec/specification/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,24 @@ module Pod
end

it 'maintains correct order of keys across versions' do
# json < 2.8.0 renders empty arrays and objects across multiple
# lines, newer versions render them compactly as [] / {}, so
# normalize empty collections before comparing.
normalize = ->(s) { s.gsub(/\[\s+\]/, '[]').gsub(/\{\s+\}/, '{}') }
%w(14 15 16 17 18).each do |version|
json = File.read(File.expand_path("../../fixtures/CannonPodder#{version}.podspec.json", __FILE__))
loaded_spec = Specification.from_json(json)
new_json = loaded_spec.to_pretty_json
normalize.call(new_json).should.equal normalize.call(json)
new_json.should.equal json
end
end

it 'renders empty collections compactly regardless of the json gem version' do
spec = Specification.new do |s|
s.name = 'Empty'
s.dependency 'Dep'
s.pod_target_xcconfig = {}
end
json = spec.to_pretty_json
json.should.include '"Dep": []'
json.should.include '"pod_target_xcconfig": {}'
end
end

#-------------------------------------------------------------------------#
Expand Down
Loading