-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Ensure trailing slash is added to source URIs added via gem sources #9055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b1e4fb1
376bcdf
3e81961
da8d622
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,82 @@ def test_execute_add | |
| assert_equal "", @ui.error | ||
| end | ||
|
|
||
| def test_execute_add_without_trailing_slash | ||
| setup_fake_source("https://rubygems.pkg.github.com/my-org") | ||
|
|
||
| @cmd.handle_options %W[--add https://rubygems.pkg.github.com/my-org] | ||
|
|
||
| use_ui @ui do | ||
| @cmd.execute | ||
| end | ||
|
|
||
| assert_equal [@gem_repo, "https://rubygems.pkg.github.com/my-org/"], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| https://rubygems.pkg.github.com/my-org/ added to sources | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
| assert_equal "", @ui.error | ||
| end | ||
|
|
||
| def test_execute_add_multiple_trailing_slash | ||
| setup_fake_source("https://rubygems.pkg.github.com/my-org/") | ||
|
|
||
| @cmd.handle_options %W[--add https://rubygems.pkg.github.com/my-org///] | ||
|
|
||
| use_ui @ui do | ||
| @cmd.execute | ||
| end | ||
|
|
||
| assert_equal [@gem_repo, "https://rubygems.pkg.github.com/my-org/"], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| https://rubygems.pkg.github.com/my-org/ added to sources | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
| assert_equal "", @ui.error | ||
| end | ||
|
|
||
| def test_execute_append_without_trailing_slash | ||
| setup_fake_source("https://rubygems.pkg.github.com/my-org") | ||
|
|
||
| @cmd.handle_options %W[--append https://rubygems.pkg.github.com/my-org] | ||
|
|
||
| use_ui @ui do | ||
| @cmd.execute | ||
| end | ||
|
|
||
| assert_equal [@gem_repo, "https://rubygems.pkg.github.com/my-org/"], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| https://rubygems.pkg.github.com/my-org/ added to sources | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
| assert_equal "", @ui.error | ||
| end | ||
|
|
||
| def test_execute_prepend_without_trailing_slash | ||
| setup_fake_source("https://rubygems.pkg.github.com/my-org") | ||
|
|
||
| @cmd.handle_options %W[--prepend https://rubygems.pkg.github.com/my-org] | ||
|
|
||
| use_ui @ui do | ||
| @cmd.execute | ||
| end | ||
|
|
||
| assert_equal ["https://rubygems.pkg.github.com/my-org/", @gem_repo], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| https://rubygems.pkg.github.com/my-org/ added to sources | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
| assert_equal "", @ui.error | ||
| end | ||
|
|
||
| def test_execute_append | ||
| setup_fake_source(@new_repo) | ||
|
|
||
|
|
@@ -530,17 +606,14 @@ def test_execute_add_https_rubygems_org | |
|
|
||
| @cmd.handle_options %W[--add #{https_rubygems_org}] | ||
|
|
||
| ui = Gem::MockGemUi.new "n" | ||
|
|
||
| use_ui ui do | ||
| assert_raise Gem::MockGemUi::TermError do | ||
| @cmd.execute | ||
| end | ||
| use_ui @ui do | ||
| @cmd.execute | ||
| end | ||
|
Comment on lines
-533
to
611
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why the existing passed with |
||
|
|
||
| assert_equal [@gem_repo], Gem.sources | ||
| assert_equal [@gem_repo, https_rubygems_org], Gem.sources | ||
|
|
||
| expected = <<-EXPECTED | ||
| #{https_rubygems_org} added to sources | ||
| EXPECTED | ||
|
|
||
| assert_equal expected, @ui.output | ||
|
|
@@ -554,17 +627,14 @@ def test_execute_append_https_rubygems_org | |
|
|
||
| @cmd.handle_options %W[--append #{https_rubygems_org}] | ||
|
|
||
| ui = Gem::MockGemUi.new "n" | ||
|
|
||
| use_ui ui do | ||
| assert_raise Gem::MockGemUi::TermError do | ||
| @cmd.execute | ||
| end | ||
| use_ui @ui do | ||
| @cmd.execute | ||
| end | ||
|
|
||
| assert_equal [@gem_repo], Gem.sources | ||
| assert_equal [@gem_repo, https_rubygems_org], Gem.sources | ||
|
|
||
| expected = <<-EXPECTED | ||
| #{https_rubygems_org} added to sources | ||
| EXPECTED | ||
|
|
||
| assert_equal expected, @ui.output | ||
|
|
@@ -583,7 +653,7 @@ def test_execute_add_bad_uri | |
| assert_equal [@gem_repo], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| beta-gems.example.com is not a URI | ||
| beta-gems.example.com/ is not a URI | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
|
|
@@ -602,7 +672,26 @@ def test_execute_append_bad_uri | |
| assert_equal [@gem_repo], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| beta-gems.example.com is not a URI | ||
| beta-gems.example.com/ is not a URI | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
| assert_equal "", @ui.error | ||
| end | ||
|
|
||
| def test_execute_prepend_bad_uri | ||
| @cmd.handle_options %w[--prepend beta-gems.example.com] | ||
|
|
||
| use_ui @ui do | ||
| assert_raise Gem::MockGemUi::TermError do | ||
| @cmd.execute | ||
| end | ||
| end | ||
|
|
||
| assert_equal [@gem_repo], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| beta-gems.example.com/ is not a URI | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
|
|
@@ -778,6 +867,31 @@ def test_execute_remove_redundant_source_trailing_slash | |
| Gem.configuration.sources = nil | ||
| end | ||
|
|
||
| def test_execute_remove_without_trailing_slash | ||
| source_uri = "https://rubygems.pkg.github.com/my-org/" | ||
|
|
||
| Gem.configuration.sources = [source_uri] | ||
|
|
||
| setup_fake_source(source_uri) | ||
|
|
||
| @cmd.handle_options %W[--remove https://rubygems.pkg.github.com/my-org] | ||
|
|
||
| use_ui @ui do | ||
| @cmd.execute | ||
| end | ||
|
|
||
| assert_equal [], Gem.sources | ||
|
|
||
| expected = <<-EOF | ||
| #{source_uri} removed from sources | ||
| EOF | ||
|
|
||
| assert_equal expected, @ui.output | ||
| assert_equal "", @ui.error | ||
| ensure | ||
| Gem.configuration.sources = nil | ||
| end | ||
|
|
||
| def test_execute_update | ||
| @cmd.handle_options %w[--update] | ||
|
|
||
|
|
@@ -888,6 +1002,6 @@ def setup_fake_source(uri) | |
| Marshal.dump specs, io | ||
| end | ||
|
|
||
| @fetcher.data["#{uri}/specs.#{@marshal_version}.gz"] = specs_dump_gz.string | ||
| @fetcher.data["#{uri.chomp("/")}/specs.#{@marshal_version}.gz"] = specs_dump_gz.string | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we revert this change if we always use URI that has a trailing slash for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without It's difficult to check for the presence or absence of slashes in every call to the helper, so I think it's reasonable to remove them here. |
||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.