diff --git a/Changes b/Changes index 6e02d507..7ba41c37 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,8 @@ Revision history for URI - Add a GH workflow to test LWP::Curl (GH#116) (Olaf Alders) - Add documentation examples for the host() and ihost() methods (GH#28) (Sebastian Willing) + - Remove colon from username:password if there is no password (GH#31) + (David E. Wheeler, Joenio Marques da Costa, Julien Fiegehenn) 5.17 2022-11-02 17:03:48Z - Updated RFC references in the pod documentation for URI::file (GH#117) diff --git a/lib/URI/_userpass.pm b/lib/URI/_userpass.pm index f422038f..2af52321 100644 --- a/lib/URI/_userpass.pm +++ b/lib/URI/_userpass.pm @@ -40,7 +40,7 @@ sub password $user =~ s/:.*//; if (!defined($new)) { - $self->userinfo($user || undef); + $self->userinfo(length $user ? $user : undef); } else { $new = "" unless defined($new); $new =~ s/%/%25/g; diff --git a/t/userpass.t b/t/userpass.t index b18aa3d3..a505d5c4 100644 --- a/t/userpass.t +++ b/t/userpass.t @@ -1,12 +1,18 @@ use strict; use warnings; -print "1..1\n"; +use Test::More; use URI; -my $uri = URI->new("rsync://foo:bar\@example.com"); +my $uri = URI->new('rsync://foo:bar@example.com'); +like $uri->as_string, qr/foo:bar\@example\.com/, 'userinfo is included'; + +$uri->password(undef); +like $uri->as_string, qr/foo\@example\.com/, 'set password to undef'; + +$uri = URI->new('rsync://0:bar@example.com'); $uri->password(undef); +like $uri->as_string, qr/0\@example\.com/, '... also for username "0"'; -print "not " if $uri->as_string =~ /foo:\@example.com/; -print "ok 1\n"; +done_testing;