diff options
author | Marc Alexander <admin@m-a-styles.de> | 2014-08-08 15:03:33 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2014-08-08 17:06:01 +0200 |
commit | a6b275de5cd96f7a2527958e510a628012041a93 (patch) | |
tree | 70fd671bd3665b3b11e39e643a585cb62e3f926a | |
parent | e4e7a8f8494922ee52d927cfcfe8b27d73452ced (diff) | |
download | forums-a6b275de5cd96f7a2527958e510a628012041a93.tar forums-a6b275de5cd96f7a2527958e510a628012041a93.tar.gz forums-a6b275de5cd96f7a2527958e510a628012041a93.tar.bz2 forums-a6b275de5cd96f7a2527958e510a628012041a93.tar.xz forums-a6b275de5cd96f7a2527958e510a628012041a93.zip |
[ticket/12794] Properly validate google+ field against valid character set
PHPBB3-12794
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_googleplus.php | 2 | ||||
-rw-r--r-- | tests/profilefields/type_googleplus_test.php | 54 |
2 files changed, 44 insertions, 12 deletions
diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 887baa3de1..e6729b1935 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -40,7 +40,7 @@ class type_googleplus extends type_string 'field_length' => 20, 'field_minlen' => 3, 'field_maxlen' => 255, - 'field_validation' => '[\w]+', + 'field_validation' => '(?:(?!\.{2,})([^<>=+]))+', 'field_novalue' => '', 'field_default_value' => '', ); diff --git a/tests/profilefields/type_googleplus_test.php b/tests/profilefields/type_googleplus_test.php index fdbdd86553..3e0af36a73 100644 --- a/tests/profilefields/type_googleplus_test.php +++ b/tests/profilefields/type_googleplus_test.php @@ -11,8 +11,27 @@ * */ +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; + class phpbb_profilefield_type_googleplus_test extends phpbb_test_case { + protected $field; + + public function setUp() + { + parent::setUp(); + + $user = new \phpbb\user(); + $user->add_lang('ucp'); + $request = $this->getMock('\phpbb\request\request'); + $template = $this->getMock('\phpbb\template\template'); + + $this->field = new \phpbb\profilefields\type\type_googleplus( + $request, + $template, + $user + ); + } public function get_profile_contact_value_data() { return array( @@ -36,16 +55,6 @@ class phpbb_profilefield_type_googleplus_test extends phpbb_test_case */ public function test_get_profile_contact_value($value, $field_options, $expected, $description) { - $user = $this->getMock('\phpbb\user'); - $request = $this->getMock('\phpbb\request\request'); - $template = $this->getMock('\phpbb\template\template'); - - $field = new \phpbb\profilefields\type\type_googleplus( - $request, - $template, - $user - ); - $default_field_options = array( 'field_type' => '\phpbb\profilefields\type\type_googleplus', 'field_name' => 'field', @@ -57,6 +66,29 @@ class phpbb_profilefield_type_googleplus_test extends phpbb_test_case ); $field_options = array_merge($default_field_options, $field_options); - $this->assertSame($expected, $field->get_profile_contact_value($value, $field_options), $description); + $this->assertSame($expected, $this->field->get_profile_contact_value($value, $field_options), $description); + } + + public function data_validate_googleplus() + { + return array( + array('foobar', false), + array('2342340929304', false), + array('foo<bar', 'The field “googleplus” has invalid characters.'), + array('klkd.klkl', false), + array('kl+', 'The field “googleplus” has invalid characters.'), + array('foo=bar', 'The field “googleplus” has invalid characters.'), + array('..foo', 'The field “googleplus” has invalid characters.'), + array('foo..bar', 'The field “googleplus” has invalid characters.'), + ); + } + + /** + * @dataProvider data_validate_googleplus + */ + public function test_validate_googleplus($input, $expected) + { + $field_data = array_merge(array('lang_name' => 'googleplus'), $this->field->get_default_option_values()); + $this->assertSame($expected, $this->field->validate_string_profile_field('string', $input, $field_data)); } } |