1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-10 16:35:35 +02:00

Merge remote-tracking branch 'nickvergessen/ticket/9066' into develop-olympus

* nickvergessen/ticket/9066:
  [ticket/9066] Move regex into get_preg_expression function and add tests
  [ticket/9066] Disallow some database prefix to prevent same errors and problems
This commit is contained in:
Andreas Fischer
2011-11-14 15:46:50 +01:00
4 changed files with 47 additions and 1 deletions

View File

@ -3486,6 +3486,10 @@ function get_preg_expression($mode)
$inline = ($mode == 'relative_url') ? ')' : '';
return "(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*(?:/(?:[a-z0-9\-._~!$&'($inline*+,;=:@|]+|%[\dA-F]{2})*)*(?:\?(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?(?:\#(?:[a-z0-9\-._~!$&'($inline*+,;=:@/?|]+|%[\dA-F]{2})*)?";
break;
case 'table_prefix':
return '#^[a-zA-Z][a-zA-Z0-9_]*$#';
break;
}
return '';

View File

@ -546,6 +546,11 @@ class install_install extends module
$error[] = $lang['INST_ERR_NO_DB'];
$connect_test = false;
}
else if (!preg_match(get_preg_expression('table_prefix'), $data['table_prefix']))
{
$error[] = $lang['INST_ERR_DB_INVALID_PREFIX'];
$connect_test = false;
}
else
{
$connect_test = connect_check_db(true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']);
@ -2032,7 +2037,7 @@ class install_install extends module
'dbname' => array('lang' => 'DB_NAME', 'type' => 'text:25:100', 'explain' => false),
'dbuser' => array('lang' => 'DB_USERNAME', 'type' => 'text:25:100', 'explain' => false),
'dbpasswd' => array('lang' => 'DB_PASSWORD', 'type' => 'password:25:100', 'explain' => false),
'table_prefix' => array('lang' => 'TABLE_PREFIX', 'type' => 'text:25:100', 'explain' => false),
'table_prefix' => array('lang' => 'TABLE_PREFIX', 'type' => 'text:25:100', 'explain' => true),
);
var $admin_config_options = array(
'legend1' => 'ADMIN_CONFIG',

View File

@ -232,6 +232,7 @@ $lang = array_merge($lang, array(
'INST_ERR' => 'Installation error',
'INST_ERR_DB_CONNECT' => 'Could not connect to the database, see error message below.',
'INST_ERR_DB_FORUM_PATH' => 'The database file specified is within your board directory tree. You should put this file in a non web-accessible location.',
'INST_ERR_DB_INVALID_PREFIX'=> 'The prefix you entered is invalid. It must start with an alphanumeric character and must only contain alphanumeric characters, numbers and underscores.',
'INST_ERR_DB_NO_ERROR' => 'No error message given.',
'INST_ERR_DB_NO_MYSQLI' => 'The version of MySQL installed on this machine is incompatible with the “MySQL with MySQLi Extension” option you have selected. Please try the “MySQL” option instead.',
'INST_ERR_DB_NO_SQLITE' => 'The version of the SQLite extension you have installed is too old, it must be upgraded to at least 2.8.2.',
@ -352,6 +353,7 @@ $lang = array_merge($lang, array(
'TABLES_MISSING' => 'Could not find these tables<br />» <strong>%s</strong>.',
'TABLE_PREFIX' => 'Prefix for tables in database',
'TABLE_PREFIX_EXPLAIN' => 'The prefix must start with an alphanumeric character and must only contain alphanumeric characters, numbers and underscores.',
'TABLE_PREFIX_SAME' => 'The table prefix needs to be the one used by the software you are converting from.<br />» Specified table prefix was %s.',
'TESTS_PASSED' => 'Tests passed',
'TESTS_FAILED' => 'Tests failed',

View File

@ -0,0 +1,35 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_regex_table_prefix_test extends phpbb_test_case
{
public function table_prefix_test_data()
{
return array(
array('phpbb_', 1),
array('phpBB3', 1),
array('a', 1),
array('', 0),
array('_', 0),
array('a-', 0),
array("'", 0),
);
}
/**
* @dataProvider table_prefix_test_data
*/
public function test_table_prefix($prefix, $expected)
{
$this->assertEquals($expected, preg_match(get_preg_expression('table_prefix'), $prefix));
}
}