diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2011-11-13 16:11:32 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2011-11-14 15:10:25 +0100 |
commit | 3302305cd4a499603784aa87a40f5170d62a4f26 (patch) | |
tree | dbba0380db1bb2ff3f8194608521ba28c336adc1 | |
parent | 6370ef27057643ee7fe0a6fbf2341c2ebdb57d4c (diff) | |
download | forums-3302305cd4a499603784aa87a40f5170d62a4f26.tar forums-3302305cd4a499603784aa87a40f5170d62a4f26.tar.gz forums-3302305cd4a499603784aa87a40f5170d62a4f26.tar.bz2 forums-3302305cd4a499603784aa87a40f5170d62a4f26.tar.xz forums-3302305cd4a499603784aa87a40f5170d62a4f26.zip |
[ticket/9066] Move regex into get_preg_expression function and add tests
PHPBB3-9066
-rw-r--r-- | phpBB/includes/functions.php | 4 | ||||
-rw-r--r-- | phpBB/install/install_install.php | 2 | ||||
-rw-r--r-- | tests/regex/table_prefix_test.php | 35 |
3 files changed, 40 insertions, 1 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c2b099d48a..e477b0454e 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 bb1d858cfc..ccdcf211f1 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -546,7 +546,7 @@ class install_install extends module $error[] = $lang['INST_ERR_NO_DB']; $connect_test = false; } - else if (!preg_match('#^[a-zA-Z][a-zA-Z0-9_]*$#', $data['table_prefix'], $result)) + else if (!preg_match(get_preg_expression('table_prefix'), $data['table_prefix'])) { $error[] = $lang['INST_ERR_DB_INVALID_PREFIX']; $connect_test = false; 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)); + } +} |