Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pull/12678' into QA_4_6
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 8, 2016
2 parents 303da92 + 9be7c55 commit 38a804e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 13 additions & 7 deletions libraries/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1259,22 +1259,28 @@ static function isValidName($table_name, $is_backquoted = false)
// trailing spaces not allowed even in backquotes
return false;
}
if (! $is_backquoted && $table_name !== trim($table_name)) {
// spaces at the start or in between
return false;
}

if (! mb_strlen($table_name)) {
// zero length
return false;
}

if (preg_match('/[.\/\\\\]+/i', $table_name)) {
// illegal char . / \
if (! $is_backquoted && $table_name !== trim($table_name)) {
// spaces at the start or in between only allowed inside backquotes
return false;
}

return true;
if (! $is_backquoted && preg_match('/^[a-zA-Z0-9_$]+$/', $table_name)) {
// only allow the above regex in unquoted identifiers
// see : http://dev.mysql.com/doc/refman/5.7/en/identifiers.html
return true;
} else if ($is_backquoted) {
// If backquoted, all characters should be allowed (except w/ trailing spaces)
return true;
}

// If not backquoted and doesn't follow the above regex
return false;
}

/**
Expand Down
14 changes: 11 additions & 3 deletions test/classes/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,12 @@ public function dataValidateName()
array('te/st', false),
array('te.st', false),
array('te\\st', false),
array('te st', true),
array('te st', false),
array(' te st', true, true),
array('test ', false),
array('te.st', false),
array('test ', false, true),
array('te.st ', false, true),
);
}

Expand Down Expand Up @@ -777,10 +779,16 @@ public function testRename()
$table_new = 'PMA_.BookMark';
$result = $table->rename($table_new);
$this->assertEquals(
false,
true,
$result
);

//message
$this->assertEquals(
"Table PMA_BookMark has been renamed to PMA_.BookMark.",
$table->getLastMessage()
);

$table_new = 'PMA_BookMark_new';
$db_new = 'PMA_new';
$result = $table->rename($table_new, $db_new);
Expand All @@ -790,7 +798,7 @@ public function testRename()
);
//message
$this->assertEquals(
"Table PMA_BookMark has been renamed to PMA_BookMark_new.",
"Table PMA_.BookMark has been renamed to PMA_BookMark_new.",
$table->getLastMessage()
);
}
Expand Down

0 comments on commit 38a804e

Please sign in to comment.