(mongodb) fix: encode username & password (#1506)

* url-encode user/pwd in MongoDB driver

* fix double declaration
This commit is contained in:
Simon Bomm 2019-05-13 14:01:52 +02:00 committed by GitHub
parent 93b93d71d4
commit 60985e37ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -25,6 +25,7 @@ use warnings;
use DateTime;
use MongoDB;
use Hash::Ordered;
use URI::Encode;
sub new {
my ($class, %options) = @_;
@ -106,8 +107,12 @@ sub get_port {
sub connect {
my ($self, %options) = @_;
my $uri = 'mongodb://';
$uri .= $self->{username} . ':' . $self->{password} . '@' if ($self->{username} ne '' && $self->{password} ne '');
my $uri = URI::Encode->new({encode_reserved => 1});
my $encoded_username = $uri->encode($self->{username});
my $encoded_password = $uri->encode($self->{password});
$uri = 'mongodb://';
$uri .= $encoded_username . ':' . $encoded_password . '@' if ($encoded_username ne '' && $encoded_password ne '');
$uri .= $self->{hostname} if ($self->{hostname} ne '');
$uri .= ':' . $self->{port} if ($self->{port} ne '');