summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Fiegehenn <simbabque@cpan.org>2023-04-29 15:20:29 +0100
committerOlaf Alders <olaf@wundersolutions.com>2023-04-29 16:32:23 +0200
commit0f2cb990c9f27e2da1b661876e24fe19d0f52bee (patch)
tree0b258425e0084b2c81074b8b65f4b371826138fd
parent30569f15d9aa3a9548bad71e4172d7639f4af372 (diff)
downloaduri-0f2cb990c9f27e2da1b661876e24fe19d0f52bee.tar.gz
protect username '0'
-rw-r--r--Changes2
-rw-r--r--lib/URI/_userpass.pm2
-rw-r--r--t/userpass.t14
3 files changed, 13 insertions, 5 deletions
diff --git a/Changes b/Changes
index 6e02d50..7ba41c3 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 f422038..2af5232 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 b18aa3d..a505d5c 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;