mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-16 00:03:02 +00:00
Separate DSN parts using escaped commas instead so bareword values work.
This commit is contained in:
@@ -34,14 +34,7 @@ $Data::Dumper::Quotekeys = 0;
|
|||||||
|
|
||||||
# Passwords may contain commas.
|
# Passwords may contain commas.
|
||||||
# https://bugs.launchpad.net/percona-toolkit/+bug/886077
|
# https://bugs.launchpad.net/percona-toolkit/+bug/886077
|
||||||
my $dsn_sep = qr/ # Separate DSN parts by
|
my $dsn_sep = qr/(?<!\\),/;
|
||||||
, # comma
|
|
||||||
(?= # followed by either
|
|
||||||
(?:\Z # the end of the string, or
|
|
||||||
|[a-zA-Z]= # start of another DSN part
|
|
||||||
)
|
|
||||||
)
|
|
||||||
/x;
|
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
require DBI;
|
require DBI;
|
||||||
@@ -140,6 +133,7 @@ sub parse {
|
|||||||
foreach my $dsn_part ( split($dsn_sep, $dsn) ) {
|
foreach my $dsn_part ( split($dsn_sep, $dsn) ) {
|
||||||
if ( my ($prop_key, $prop_val) = $dsn_part =~ m/^(.)=(.*)$/ ) {
|
if ( my ($prop_key, $prop_val) = $dsn_part =~ m/^(.)=(.*)$/ ) {
|
||||||
# Handle the typical DSN parts like h=host, P=3306, etc.
|
# Handle the typical DSN parts like h=host, P=3306, etc.
|
||||||
|
$prop_val =~ s/\\,/,/g;
|
||||||
$given_props{$prop_key} = $prop_val;
|
$given_props{$prop_key} = $prop_val;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More tests => 33;
|
use Test::More tests => 35;
|
||||||
|
|
||||||
use DSNParser;
|
use DSNParser;
|
||||||
use OptionParser;
|
use OptionParser;
|
||||||
@@ -483,7 +483,6 @@ SKIP: {
|
|||||||
# Passwords with commas don't work, expose part of password
|
# Passwords with commas don't work, expose part of password
|
||||||
# https://bugs.launchpad.net/percona-toolkit/+bug/886077
|
# https://bugs.launchpad.net/percona-toolkit/+bug/886077
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
$dp = new DSNParser(opts => $opts);
|
|
||||||
|
|
||||||
sub test_password_comma {
|
sub test_password_comma {
|
||||||
my ($dsn_string, $pass, $port, $name) = @_;
|
my ($dsn_string, $pass, $port, $name) = @_;
|
||||||
@@ -504,16 +503,43 @@ sub test_password_comma {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my @password_commas = (
|
my @password_commas = (
|
||||||
['u=a,p=foo,xxx,P=12345', 'foo,xxx', 12345, 'Pass with comma'],
|
['u=a,p=foo\,xxx,P=12345', 'foo,xxx', 12345, 'Pass with comma'],
|
||||||
['u=a,p=foo,xxx', 'foo,xxx', undef, 'Pass with comma, last part'],
|
['u=a,p=foo\,xxx', 'foo,xxx', undef, 'Pass with comma, last part'],
|
||||||
['u=a,p=foo,,P=12345', 'foo,', 12345, 'Pass ends with comma'],
|
['u=a,p=foo\,,P=12345', 'foo,', 12345, 'Pass ends with comma'],
|
||||||
['u=a,p=foo,,', 'foo,', undef, 'Pass ends with comma, last part'],
|
['u=a,p=foo\,', 'foo,', undef, 'Pass ends with comma, last part'],
|
||||||
['u=a,p=,,P=12345', ',', 12345, 'Pass is a comma'],
|
['u=a,p=\,,P=12345', ',', 12345, 'Pass is a comma'],
|
||||||
);
|
);
|
||||||
foreach my $password_comma ( @password_commas ) {
|
foreach my $password_comma ( @password_commas ) {
|
||||||
test_password_comma(@$password_comma);
|
test_password_comma(@$password_comma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub test_password_comma_with_auto {
|
||||||
|
my ($dsn_string, $pass, $port, $name) = @_;
|
||||||
|
my $dsn = $dp->parse($dsn_string);
|
||||||
|
is_deeply(
|
||||||
|
$dsn,
|
||||||
|
{ u => undef,
|
||||||
|
p => $pass,
|
||||||
|
S => undef,
|
||||||
|
h => 'host',
|
||||||
|
P => $port,
|
||||||
|
F => undef,
|
||||||
|
D => undef,
|
||||||
|
A => undef,
|
||||||
|
},
|
||||||
|
"$name (bug 886077)"
|
||||||
|
) or diag(Dumper($dsn));
|
||||||
|
}
|
||||||
|
|
||||||
|
@password_commas = (
|
||||||
|
['host,p=a\,z,P=9', 'a,z', 9, 'Comma-pass with leading bareword host'],
|
||||||
|
['p=a\,z,P=9,host', 'a,z', 9, 'Comma-pass with trailing bareword host'],
|
||||||
|
|
||||||
|
);
|
||||||
|
foreach my $password_comma ( @password_commas ) {
|
||||||
|
test_password_comma_with_auto(@$password_comma);
|
||||||
|
}
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
Reference in New Issue
Block a user