diff --git a/bin/pt-config-diff b/bin/pt-config-diff index 32d76421..a08df2a8 100755 --- a/bin/pt-config-diff +++ b/bin/pt-config-diff @@ -2171,6 +2171,13 @@ sub _parse_varvals { $val = ''; } else { + $val =~ s/ + \A # Start of value + (['"]) # Opening quote + (.*) # Value + \1 # Closing quote + [\n\r]*\z # End of value + /$2/x; if ( my ($num, $factor) = $val =~ m/(\d+)([KMGT])b?$/i ) { my %factor_for = ( k => 1_024, diff --git a/lib/MySQLConfig.pm b/lib/MySQLConfig.pm index 5cdf857f..703cada5 100644 --- a/lib/MySQLConfig.pm +++ b/lib/MySQLConfig.pm @@ -371,6 +371,13 @@ sub _parse_varvals { $val = ''; } else { + $val =~ s/ + \A # Start of value + (['"]) # Opening quote + (.*) # Value + \1 # Closing quote + [\n\r]*\z # End of value + /$2/x; if ( my ($num, $factor) = $val =~ m/(\d+)([KMGT])b?$/i ) { # value is a size like 1k, 16M, etc. my %factor_for = ( diff --git a/t/lib/MySQLConfigComparer.t b/t/lib/MySQLConfigComparer.t index 46b1d5c9..f3f04e5c 100644 --- a/t/lib/MySQLConfigComparer.t +++ b/t/lib/MySQLConfigComparer.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 16; +use Test::More; use TextResultSetParser(); use MySQLConfigComparer; @@ -369,6 +369,29 @@ $c2 = new MySQLConfig( ) or print Dumper($diff); } +# ############################################################################ +# https://bugs.launchpad.net/percona-toolkit/+bug/889739 +# pt-config-diff doesn't diff quoted strings properly +# ############################################################################ +$c1 = new MySQLConfig( + file => "$trunk/$sample/quoted_cnf.txt", + TextResultSetParser => $trp, +); +$c2 = new MySQLConfig( + file => "$trunk/$sample/unquoted_cnf.txt", + TextResultSetParser => $trp, +); +{ + my $diff = $cc->diff( + configs => [$c1, $c2], + ); + + is_deeply( + $diff, + undef, + "Values are the same regardless of quoting" + ) or diag(Dumper($diff)); +} # ############################################################################# # Done. # ############################################################################# @@ -382,4 +405,5 @@ like( qr/Complete test coverage/, '_d() works' ); -exit; + +done_testing; diff --git a/t/lib/samples/configs/quoted_cnf.txt b/t/lib/samples/configs/quoted_cnf.txt new file mode 100644 index 00000000..2103679d --- /dev/null +++ b/t/lib/samples/configs/quoted_cnf.txt @@ -0,0 +1,6 @@ +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + +[mysqld] +init-connect='SET NAMES utf8' diff --git a/t/lib/samples/configs/unquoted_cnf.txt b/t/lib/samples/configs/unquoted_cnf.txt new file mode 100644 index 00000000..5ecd72d9 --- /dev/null +++ b/t/lib/samples/configs/unquoted_cnf.txt @@ -0,0 +1,6 @@ +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + +[mysqld] +init-connect=SET NAMES utf8 diff --git a/t/lib/samples/empty.txt b/t/lib/samples/empty.txt new file mode 100644 index 00000000..e69de29b