From b1ab1ee046816b021a3cbd0a08bfce0e459beb4b Mon Sep 17 00:00:00 2001 From: huangduirong Date: Thu, 9 Sep 2021 15:24:41 +0800 Subject: [PATCH] [rubygems/rubygems] Fix error message building changing password of source Do not change the password of the input parameter source during anonymization, by using the proper helper instead of changing the original uri directly. https://github.com/rubygems/rubygems/commit/eaa2dd8a97 --- lib/rubygems/errors.rb | 3 +-- test/rubygems/test_gem_source_fetch_problem.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb index abee20651e..86f0d1da14 100644 --- a/lib/rubygems/errors.rb +++ b/lib/rubygems/errors.rb @@ -171,8 +171,7 @@ module Gem # An English description of the error. def wordy - @source.uri.password = 'REDACTED' unless @source.uri.password.nil? - "Unable to download data from #{@source.uri} - #{@error.message}" + "Unable to download data from #{Gem::Uri.new(@source.uri).redacted} - #{@error.message}" end ## diff --git a/test/rubygems/test_gem_source_fetch_problem.rb b/test/rubygems/test_gem_source_fetch_problem.rb index 0b1472c0c6..816407781d 100644 --- a/test/rubygems/test_gem_source_fetch_problem.rb +++ b/test/rubygems/test_gem_source_fetch_problem.rb @@ -23,4 +23,14 @@ class TestGemSourceFetchProblem < Gem::TestCase refute_match sf.wordy, 'secret' end + + def test_source_password_no_redacted + source = Gem::Source.new 'https://username:secret@gemsource.com' + error = RuntimeError.new 'test' + + sf = Gem::SourceFetchProblem.new source, error + sf.wordy + + assert_match 'secret', source.uri.to_s + end end