Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/MongoDB/_URI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ sub __userinfo_invalid_chars {
# redact user credentials when stringifying
use overload
'""' => sub {
(my $s = $_[0]->uri) =~ s{^(\w+)://[^/]+\@}{$1://[**REDACTED**]\@};
(my $s = $_[0]->uri) =~ s{^([^:]+)://[^/]+\@}{$1://[**REDACTED**]\@};
return $s
},
'fallback' => 1;
Expand Down
17 changes: 17 additions & 0 deletions t/unit/uri.t
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,21 @@ subtest "auth credentials" => sub {
);
};

subtest "stringification" => sub {
# For srv uri parsing and tests, see uri_srv.t
my $uri;

$uri = new_ok( $class, [ uri => 'mongodb://fred:foobar@localhost' ] );
is( "$uri", 'mongodb://[**REDACTED**]@localhost', "stringify correct" );

$uri = new_ok( $class, [ uri => 'mongodb://:@localhost' ] );
is( "$uri", 'mongodb://[**REDACTED**]@localhost', "stringify correct" );

$uri = new_ok( $class, [ uri => 'mongodb://@localhost' ] );
is( "$uri", 'mongodb://@localhost', "stringify correct" );

$uri = new_ok( $class, [ uri => 'mongodb://localhost' ] );
is( "$uri", 'mongodb://localhost', "stringify correct" );
};

done_testing;
18 changes: 17 additions & 1 deletion t/unit/uri_srv.t
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,23 @@ subtest "boolean params unchanged" => sub {
is $sslVal, 'true', 'SSL true';

is $expires, 1, 'expires as expected';
}
};
};

subtest "stringification" => sub {
my $uri = new_ok( $class, [
uri => 'mongodb+srv://testpass@testmongo.example.com',
_test_seedlist_return => [
[{ target => 'localhost', port => 27017 }],
{
retryWrites => 'true',
retryReads => 'false',
},
0
]
]);

is "$uri", 'mongodb+srv://[**REDACTED**]@testmongo.example.com', 'Stringification for SRV urls correct';
};

done_testing;