Skip to content

Commit fd55c7e

Browse files
hsbtclaude
andcommitted
Apply trailing slash normalization to remove_source as well
When sources are added with `add_trailing_slash`, the stored URI gets a trailing slash. Without the same normalization on remove, users cannot delete a source using the original URI they typed (without trailing slash). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1ff696e commit fd55c7e

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

lib/rubygems/commands/sources_command.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ def execute
289289
end
290290

291291
def remove_source(source_uri) # :nodoc:
292+
source_uri = add_trailing_slash(source_uri)
292293
source = Gem::Source.new source_uri
293294

294295
if configured_sources&.include? source

test/rubygems/test_gem_commands_sources_command.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,33 @@ def test_execute_remove_redundant_source_trailing_slash
864864
assert_equal false, Gem.sources.include?(source)
865865

866866
expected = <<-EOF
867-
#{repo_without_slash} removed from sources
867+
#{repo_with_slash} removed from sources
868+
EOF
869+
870+
assert_equal expected, @ui.output
871+
assert_equal "", @ui.error
872+
ensure
873+
Gem.configuration.sources = nil
874+
end
875+
876+
def test_execute_remove_without_trailing_slash
877+
source_uri = "https://rubygems.pkg.github.com/my-org/"
878+
879+
Gem.configuration.sources = [source_uri]
880+
881+
setup_fake_source(source_uri)
882+
883+
@cmd.handle_options %W[--remove https://rubygems.pkg.github.com/my-org]
884+
885+
use_ui @ui do
886+
@cmd.execute
887+
end
888+
889+
source = Gem::Source.new source_uri
890+
assert_equal false, Gem.sources.include?(source)
891+
892+
expected = <<-EOF
893+
#{source_uri} removed from sources
868894
EOF
869895

870896
assert_equal expected, @ui.output

0 commit comments

Comments
 (0)