Skip to content

Commit

Permalink
protect username '0'
Browse files Browse the repository at this point in the history
  • Loading branch information
simbabque authored and oalders committed Apr 29, 2023
1 parent 30569f1 commit 0f2cb99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/URI/_userpass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions t/userpass.t
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0f2cb99

Please sign in to comment.