diff --git a/lib/URI/_userpass.pm b/lib/URI/_userpass.pm index 1cef8f5d..f422038f 100644 --- a/lib/URI/_userpass.pm +++ b/lib/URI/_userpass.pm @@ -39,8 +39,8 @@ sub password my $user = defined($info) ? $info : ""; $user =~ s/:.*//; - if (!defined($new) && !length($user)) { - $self->userinfo(undef); + if (!defined($new)) { + $self->userinfo($user || undef); } else { $new = "" unless defined($new); $new =~ s/%/%25/g; diff --git a/t/userpass.t b/t/userpass.t new file mode 100644 index 00000000..b18aa3d3 --- /dev/null +++ b/t/userpass.t @@ -0,0 +1,12 @@ +use strict; +use warnings; + +print "1..1\n"; + +use URI; + +my $uri = URI->new("rsync://foo:bar\@example.com"); +$uri->password(undef); + +print "not " if $uri->as_string =~ /foo:\@example.com/; +print "ok 1\n";