From 77c7e15a67ae4eff724158b7faf841af0f4a56c2 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 1 May 2026 12:04:49 +0900 Subject: [ruby/rubygems] Reject `override :all, version:` in Bundler::Dsl Version requirements are per-gem and have no meaning relative to the `:all` target. Raise ArgumentError at the DSL entry point and store nothing when this combination is given, even if other valid fields are mixed in the same call. https://github.com/ruby/rubygems/commit/aabf71f46f Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/bundler/dsl.rb | 4 ++++ spec/bundler/bundler/dsl_spec.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index a5df3235b1..7a4fc3909e 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -186,6 +186,10 @@ module Bundler end def override(target, **operations) + if target == :all && operations.key?(:version) + raise ArgumentError, "`override :all, version:` is not allowed; version requirements are per-gem" + end + operations.each do |field, operation| @overrides << Override.new(target, field, operation) end diff --git a/spec/bundler/bundler/dsl_spec.rb b/spec/bundler/bundler/dsl_spec.rb index b0aa0fa05d..d5e5f830ce 100644 --- a/spec/bundler/bundler/dsl_spec.rb +++ b/spec/bundler/bundler/dsl_spec.rb @@ -397,5 +397,24 @@ RSpec.describe Bundler::Dsl do it "is empty by default" do expect(subject.overrides).to eq([]) end + + it "raises ArgumentError when target is :all and version: is given" do + expect do + subject.override(:all, version: ">= 8.0") + end.to raise_error(ArgumentError, /`override :all, version:` is not allowed/) + end + + it "rejects :all + version: even when other fields are also given" do + expect do + subject.override(:all, required_ruby_version: :ignore_upper, version: ">= 8.0") + end.to raise_error(ArgumentError, /`override :all, version:` is not allowed/) + end + + it "does not record any override when :all + version: is rejected" do + expect do + subject.override(:all, version: ">= 8.0") + end.to raise_error(ArgumentError) + expect(subject.overrides).to eq([]) + end end end -- cgit v1.2.3