Simplified split_grants() and added a test for mixed table & column grants on the same table

This commit is contained in:
Brian Fraser
2012-11-01 06:15:54 -03:00
parent 0fd9239500
commit a5a23665fe
3 changed files with 23 additions and 12 deletions

View File

@@ -1887,19 +1887,15 @@ sub split_grants {
my @grants; my @grants;
if ( $grants =~ m/(?:INSERT|SELECT|UPDATE) \(/ ) { if ( $grants =~ m/(?:INSERT|SELECT|UPDATE) \(/ ) {
PTDEBUG && _d('Splitting grants on keywords:', $grants); PTDEBUG && _d('Splitting grants on keywords:', $grants);
@grants = map { # TODO: the following .+? might break (e.g. on `annoying)column`).
my $grant = $_; # Remember to update this whenever we switch to using
$grant =~ s/^\s+//; # a common SQL regex module
$grant =~ s/,\s*$//; @grants = $grants =~ m/
$grant; (
} $grants =~ m/ (?:INSERT|SELECT|UPDATE)\s\(.+?\) # a column grants
\G # Start matching after the previous match | [A-Z\s]+
\s? # Space after previous match's separating comma
(?: # Either match...
(?: (?:INSERT|SELECT|UPDATE)\s\(.+?\) ) # a column grant
| (?: [A-Z\s]+ ) # or a table grant
) )
,? # Separted from the next grant, if any, by a comma (?:,\s)? # Separted from the next grant, if any, by a comma
/xg; /xg;
} }
else { else {

View File

@@ -128,6 +128,17 @@ ok(
"Column-level grants --separate --revoke (bug 866075)" "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'\@'%'"`); diag(`/tmp/12345/use -u root -e "DROP USER 'sally'\@'%'"`);
# ############################################################################# # #############################################################################

View File

@@ -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'@'%';