diff --git a/lib/pact/provider/pact_uri.rb b/lib/pact/provider/pact_uri.rb index f8df43de..56640a6e 100644 --- a/lib/pact/provider/pact_uri.rb +++ b/lib/pact/provider/pact_uri.rb @@ -30,7 +30,11 @@ def password def to_s if basic_auth? && http_or_https_uri? - URI(@uri).tap { |x| x.userinfo="#{username}:*****"}.to_s + begin + URI(@uri).tap { |x| x.userinfo="#{username}:*****"}.to_s + rescue URI::InvalidComponentError + URI(@uri).tap { |x| x.userinfo="*****:*****"}.to_s + end elsif personal_access_token? && http_or_https_uri? URI(@uri).tap { |x| x.userinfo="*****"}.to_s else @@ -45,7 +49,7 @@ def to_s private def http_or_https_uri? uri.start_with?('http://', 'https://') end - + end end end diff --git a/spec/lib/pact/provider/pact_uri_spec.rb b/spec/lib/pact/provider/pact_uri_spec.rb index 215fa33b..f7b6df6c 100644 --- a/spec/lib/pact/provider/pact_uri_spec.rb +++ b/spec/lib/pact/provider/pact_uri_spec.rb @@ -38,6 +38,14 @@ expect(pact_uri.to_s).to eq uri end end + + context "with a username that has an @ symbol" do + let(:username) { "foo@bar" } + + it 'does not blow up' do + expect(pact_uri.to_s).to eq "http://*****:*****@uri" + end + end end context 'with personal access token provided' do