summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2026-02-13 13:53:57 +0900
committergit <svn-admin@ruby-lang.org>2026-02-13 05:29:05 +0000
commit00440871dbe648cf7f8e2ebc2f01d3b1e0024cd6 (patch)
tree350a8f6093282a83a045c08bde6bdfa3362037d0
parente064d0d92518209329297cb756f22a2287efd25a (diff)
[ruby/rubygems] Relax gem name validation to warn on capital letters
https://github.com/ruby/rubygems/commit/26dab848c5
-rw-r--r--lib/bundler/cli/gem.rb8
-rw-r--r--spec/bundler/commands/newgem_spec.rb10
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 783a833e77..e681326401 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -430,11 +430,15 @@ module Bundler
end
def ensure_safe_gem_name(name, constant_array)
- if /(^\d)|[A-Z]/.match?(name)
- Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers nor include capital letters."
+ if /^\d/.match?(name)
+ Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
exit 1
end
+ if /[A-Z]/.match?(name)
+ Bundler.ui.warn "Gem names with capital letters are not recommended. Please use only lowercase letters, numbers, and hyphens."
+ end
+
constant_name = constant_array.join("::")
existing_constant = constant_array.inject(Object) do |c, s|
diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb
index 32f5e790af..26e27968b3 100644
--- a/spec/bundler/commands/newgem_spec.rb
+++ b/spec/bundler/commands/newgem_spec.rb
@@ -1982,9 +1982,17 @@ Usage: "bundle gem NAME [OPTIONS]"
it { expect(err).to include("Invalid gem name #{subject}") }
end
+ context "starting with a number" do
+ subject { "1gem" }
+ it { expect(err).to include("Invalid gem name #{subject}") }
+ end
+
context "including capital letter" do
subject { "CAPITAL" }
- it { expect(err).to include("Invalid gem name #{subject}") }
+ it "should warn but not error" do
+ expect(err).to include("Gem names with capital letters are not recommended")
+ expect(bundled_app("#{subject}/#{subject}.gemspec")).to exist
+ end
end
context "starting with an existing const name" do