File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -153,8 +153,13 @@ def parse_metadata(data)
153153 next unless v
154154 case k . to_s
155155 when "checksum"
156+ # Some registries send empty checksum values, treat them as if the
157+ # checksum was not included at all
158+ checksum = v . last
159+ next unless checksum
160+
156161 begin
157- @checksum = Checksum . from_api ( v . last , @spec_fetcher . uri )
162+ @checksum = Checksum . from_api ( checksum , @spec_fetcher . uri )
158163 rescue ArgumentError => e
159164 raise ArgumentError , "Invalid checksum for #{ full_name } : #{ e . message } "
160165 end
Original file line number Diff line number Diff line change 7171 end
7272 end
7373
74+ context "when the metadata has an empty checksum value" do
75+ let ( :metadata ) { { "checksum" => [ ] } }
76+
77+ it "leaves checksum as nil without raising" do
78+ expect ( subject . checksum ) . to be_nil
79+ end
80+ end
81+
82+ context "when the metadata has a nil checksum value" do
83+ let ( :metadata ) { { "checksum" => nil } }
84+
85+ it "leaves checksum as nil without raising" do
86+ expect ( subject . checksum ) . to be_nil
87+ end
88+ end
89+
90+ context "when the metadata has an invalid checksum value" do
91+ let ( :metadata ) { { "checksum" => [ "xyz" ] } }
92+ let ( :spec_fetcher ) { double ( :spec_fetcher , uri : "https://rubygems.org" ) }
93+
94+ it "raises an error mentioning the invalid checksum" do
95+ expect { subject } . to raise_error (
96+ Bundler ::GemspecError ,
97+ a_string_including ( "Invalid checksum for foo-1.0.0" )
98+ )
99+ end
100+ end
101+
74102 context "when the metadata has no created_at" do
75103 let ( :metadata ) { { "checksum" => [ "abc" ] } }
76104 let ( :spec_fetcher ) { double ( :spec_fetcher , uri : "https://rubygems.org" ) }
Original file line number Diff line number Diff line change 137137 sha = git . ref_for ( "main" , 11 )
138138 spec_file = scoped_gem_path ( bundled_app ( "vendor/dir[1]" ) ) . join ( "bundler/gems/foo-1.0-#{ sha } /foo.gemspec" )
139139 expect ( spec_file ) . to exist
140- ruby_code = Gem ::Specification . load ( spec_file . to_s ) . to_ruby
140+ # Serialize with the RubyGems that wrote the file, since `#to_ruby`
141+ # output differs across RubyGems versions
142+ ruby "print Gem::Specification.load(#{ spec_file . to_s . dump } ).to_ruby"
143+ ruby_code = out
141144 file_code = File . read ( spec_file )
142- expect ( file_code ) . to eq ( ruby_code )
145+ expect ( file_code . strip ) . to eq ( ruby_code )
143146 end
144147
145148 it "does not update the git source implicitly" do
You can’t perform that action at this time.
0 commit comments