diff options
author | Martin Emde <martin.emde@gmail.com> | 2023-09-01 15:15:49 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-10-23 13:59:01 +0900 |
commit | c667de72ff9de195e1cab4b1937973e841ff89ae (patch) | |
tree | 6dc6a88dbf8c44109593352055c8e798d562a83f /lib/bundler/lockfile_parser.rb | |
parent | 6362bfdc337c1929a381734ded417b796f9767bf (diff) |
[rubygems/rubygems] Improve errors and register checksums reliably
Improve error reporting for checksums, raises a new error class.
Solve for multi-source checksum errors.
Add CHECKSUMS to tool/bundler/(dev|standard|rubocop)26_gems.rb
https://github.com/rubygems/rubygems/commit/26ceee0e76
Co-authored-by: Samuel Giddins <segiddins@segiddins.me>
Diffstat (limited to 'lib/bundler/lockfile_parser.rb')
-rw-r--r-- | lib/bundler/lockfile_parser.rb | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 9ffe5beffd..2f00da7ea9 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -101,7 +101,10 @@ module Bundler "Run `git checkout HEAD -- #{@lockfile_path}` first to get a clean lock." end - lockfile.split(/((?:\r?\n)+)/).each_slice(2) do |line, whitespace| + lockfile.split(/((?:\r?\n)+)/) do |line| + # split alternates between the line and the following whitespace + next @pos.advance!(line) if line.match?(/^\s*$/) + if SOURCE.include?(line) @parse_method = :parse_source parse_source(line) @@ -121,7 +124,6 @@ module Bundler send(@parse_method, line) end @pos.advance!(line) - @pos.advance!(whitespace) end @specs = @specs.values.sort_by!(&:full_name) rescue ArgumentError => e @@ -217,23 +219,23 @@ module Bundler spaces = $1 return unless spaces.size == 2 + checksums = $6 + return unless checksums name = $2 version = $3 platform = $4 - checksums = $6 - return unless checksums version = Gem::Version.new(version) platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY - full_name = GemHelpers.spec_full_name(name, version, platform) + full_name = Gem::NameTuple.new(name, version, platform).full_name # Don't raise exception if there's a checksum for a gem that's not in the lockfile, # we prefer to heal invalid lockfiles return unless spec = @specs[full_name] - checksums.split(",").each do |c| - algo, digest = c.split("-", 2) - lock_name = GemHelpers.lock_name(spec.name, spec.version, spec.platform) - spec.source.checksum_store.register(full_name, Checksum.new(algo, digest, "#{@lockfile_path}:#{@pos} CHECKSUMS #{lock_name}")) + checksums.split(",") do |lock_checksum| + column = line.index(lock_checksum) + 1 + checksum = Checksum.from_lock(lock_checksum, "#{@lockfile_path}:#{@pos.line}:#{column}") + spec.source.checksum_store.register(spec, checksum) end end |