diff options
-rw-r--r-- | phpBB/includes/functions.php | 4 | ||||
-rw-r--r-- | phpBB/install/install_install.php | 7 | ||||
-rw-r--r-- | phpBB/language/en/install.php | 2 | ||||
-rw-r--r-- | tests/regex/table_prefix_test.php | 35 |
4 files changed, 47 insertions, 1 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8017c379f3..817111491f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -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 ''; diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 9fe0c8aed5..ccdcf211f1 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -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', diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index befa7c6f40..f038177df4 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -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', diff --git a/tests/regex/table_prefix_test.php b/tests/regex/table_prefix_test.php new file mode 100644 index 0000000000..67a18b4fbc --- /dev/null +++ b/tests/regex/table_prefix_test.php @@ -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)); + } +} |