From 0dd8c6157d4ef3e3584b5f87f4af82e3d56339e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 17 Jan 2022 14:42:41 +0100 Subject: [PATCH] [rubygems/rubygems] Don't pass regexp to `Gem::Dependency.new` during `gem dependency` https://github.com/rubygems/rubygems/commit/89dd5158a4 --- lib/rubygems/commands/dependency_command.rb | 42 ++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb index 34ec2f6852..d2fed022fe 100644 --- a/lib/rubygems/commands/dependency_command.rb +++ b/lib/rubygems/commands/dependency_command.rb @@ -53,41 +53,41 @@ use with other commands. "#{program_name} REGEXP" end - def fetch_remote_specs(dependency) # :nodoc: + def fetch_remote_specs(name, requirement, prerelease) # :nodoc: fetcher = Gem::SpecFetcher.fetcher - ss, = fetcher.spec_for_dependency dependency + specs_type = prerelease ? :complete : :released - ss.map {|spec, _| spec } + ss = if name.nil? + fetcher.detect(specs_type) { true } + else + fetcher.detect(specs_type) do |name_tuple| + name === name_tuple.name && requirement.satisfied_by?(name_tuple.version) + end + end + + ss.map {|tuple, source| source.fetch_spec(tuple) } end - def fetch_specs(name_pattern, dependency) # :nodoc: + def fetch_specs(name_pattern, requirement, prerelease) # :nodoc: specs = [] if local? specs.concat Gem::Specification.stubs.find_all {|spec| - name_pattern =~ spec.name and - dependency.requirement.satisfied_by? spec.version + name_matches = name_pattern ? name_pattern =~ spec.name : true + version_matches = requirement.satisfied_by?(spec.version) + + name_matches and version_matches }.map(&:to_spec) end - specs.concat fetch_remote_specs dependency if remote? + specs.concat fetch_remote_specs name_pattern, requirement, prerelease if remote? ensure_specs specs specs.uniq.sort end - def gem_dependency(pattern, version, prerelease) # :nodoc: - dependency = Gem::Deprecate.skip_during do - Gem::Dependency.new pattern, version - end - - dependency.prerelease = prerelease - - dependency - end - def display_pipe(specs) # :nodoc: specs.each do |spec| unless spec.dependencies.empty? @@ -119,11 +119,9 @@ use with other commands. ensure_local_only_reverse_dependencies pattern = name_pattern options[:args] + requirement = Gem::Requirement.new options[:version] - dependency = - gem_dependency pattern, options[:version], options[:prerelease] - - specs = fetch_specs pattern, dependency + specs = fetch_specs pattern, requirement, options[:prerelease] reverse = reverse_dependencies specs @@ -197,7 +195,7 @@ use with other commands. private def name_pattern(args) - args << '' if args.empty? + return if args.empty? if args.length == 1 and args.first =~ /\A(.*)(i)?\z/m flags = $2 ? Regexp::IGNORECASE : nil