From bb5d64b4a6a7af4dd44b18336b635e10576a6c3a Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 24 May 2012 11:20:38 -0600 Subject: [PATCH] Remove \, from any DSN part (value or bareword). Document that DSN values must be escaped. --- docs/percona-toolkit.pod | 14 ++++++++++++++ lib/DSNParser.pm | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/percona-toolkit.pod b/docs/percona-toolkit.pod index 73d0b6bf..5cba1d81 100644 --- a/docs/percona-toolkit.pod +++ b/docs/percona-toolkit.pod @@ -313,6 +313,20 @@ provide defaults for all DSNs that do not specify the option's corresponding key part. For example, if DSN C and option C<--port=12345> are specified, then the tool automatically adds C to DSN. +=head2 ESCAPING VALUES + +DSNs are usually specified on the command line, so shell quoting and escaping +must be taken into account. Special characters, like asterisk (C<*>), need +to be quoted and/or escaped properly to be passed as literal characters in +DSN values. + +Since DSN parts are separated by commas, literal commas in DSN values must +be escaped with a single backslash (C<\>). And since a backslash is +the escape character for most shells, two backslashes are required to pass +a literal backslash. For example, if the username is literally C, +it must be specified as C on most shells. This applies to DSNs +and DSN-related options like C<--user>. + =head2 KEY PARTS Many of the tools add more parts to DSNs for special purposes, and sometimes diff --git a/lib/DSNParser.pm b/lib/DSNParser.pm index fd7b4f1b..938ec37b 100644 --- a/lib/DSNParser.pm +++ b/lib/DSNParser.pm @@ -131,9 +131,9 @@ sub parse { # Parse given props foreach my $dsn_part ( split($dsn_sep, $dsn) ) { + $dsn_part =~ s/\\,/,/g; if ( my ($prop_key, $prop_val) = $dsn_part =~ m/^(.)=(.*)$/ ) { # Handle the typical DSN parts like h=host, P=3306, etc. - $prop_val =~ s/\\,/,/g; $given_props{$prop_key} = $prop_val; } else {