From a5a23665feea30e672fcc63d530c3d95dbd65bd0 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Thu, 1 Nov 2012 06:15:54 -0300 Subject: [PATCH] Simplified split_grants() and added a test for mixed table & column grants on the same table --- bin/pt-show-grants | 20 ++++++++----------- t/pt-show-grants/basics.t | 11 ++++++++++ .../samples/column-grants-combined.txt | 4 ++++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 t/pt-show-grants/samples/column-grants-combined.txt diff --git a/bin/pt-show-grants b/bin/pt-show-grants index 99f90d53..d73a6157 100755 --- a/bin/pt-show-grants +++ b/bin/pt-show-grants @@ -1887,19 +1887,15 @@ sub split_grants { my @grants; if ( $grants =~ m/(?:INSERT|SELECT|UPDATE) \(/ ) { PTDEBUG && _d('Splitting grants on keywords:', $grants); - @grants = map { - my $grant = $_; - $grant =~ s/^\s+//; - $grant =~ s/,\s*$//; - $grant; - } $grants =~ m/ - \G # Start matching after the previous match - \s? # Space after previous match's separating comma - (?: # Either match... - (?: (?:INSERT|SELECT|UPDATE)\s\(.+?\) ) # a column grant - | (?: [A-Z\s]+ ) # or a table grant + # TODO: the following .+? might break (e.g. on `annoying)column`). + # Remember to update this whenever we switch to using + # a common SQL regex module + @grants = $grants =~ m/ + ( + (?:INSERT|SELECT|UPDATE)\s\(.+?\) # a column grants + | [A-Z\s]+ ) - ,? # Separted from the next grant, if any, by a comma + (?:,\s)? # Separted from the next grant, if any, by a comma /xg; } else { diff --git a/t/pt-show-grants/basics.t b/t/pt-show-grants/basics.t index 5c739c7e..d526ffea 100644 --- a/t/pt-show-grants/basics.t +++ b/t/pt-show-grants/basics.t @@ -128,6 +128,17 @@ ok( "Column-level grants --separate --revoke (bug 866075)" ); +diag(`/tmp/12345/use -u root -e "GRANT SELECT ON sakila.city TO 'sally'\@'%'"`); + +ok( + no_diff( + sub { pt_show_grants::main('-F', $cnf, qw(--only sally --no-header)) }, + "t/pt-show-grants/samples/column-grants-combined.txt", + stderr => 1, + ), + "Column-level grants combined with table-level grants on the same table (bug 866075)" +); + diag(`/tmp/12345/use -u root -e "DROP USER 'sally'\@'%'"`); # ############################################################################# diff --git a/t/pt-show-grants/samples/column-grants-combined.txt b/t/pt-show-grants/samples/column-grants-combined.txt new file mode 100644 index 00000000..fd679980 --- /dev/null +++ b/t/pt-show-grants/samples/column-grants-combined.txt @@ -0,0 +1,4 @@ +-- Grants for 'sally'@'%' +GRANT INSERT (city), SELECT, SELECT (city_id) ON `sakila`.`city` TO 'sally'@'%'; +GRANT SELECT (SANumber, DateCreated, PaymentStat, PckPrice) ON `test`.`t` TO 'sally'@'%'; +GRANT USAGE ON *.* TO 'sally'@'%';