From 8360752b2abf594ad458fcfcbfbfa02886336f21 Mon Sep 17 00:00:00 2001 From: toxyy Date: Tue, 12 Sep 2023 00:34:54 -0400 Subject: [PATCH 1/3] [ticket/17188] Allow request variable to check multiline unicode Change set_var to check for multiline strings if multibyte PHPBB3-17188 --- phpBB/phpbb/request/type_cast_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/request/type_cast_helper.php b/phpBB/phpbb/request/type_cast_helper.php index 3f793d1c5d..ff81b7130f 100644 --- a/phpBB/phpbb/request/type_cast_helper.php +++ b/phpBB/phpbb/request/type_cast_helper.php @@ -55,7 +55,7 @@ class type_cast_helper implements \phpbb\request\type_cast_helper_interface // Make sure multibyte characters are wellformed if ($multibyte) { - if (!preg_match('/^./u', $result)) + if (!preg_match('/^./um', $result)) { $result = ''; } From d59a4d4aad9668a4ca961f93aafc85de854fd99c Mon Sep 17 00:00:00 2001 From: toxyy Date: Sat, 16 Sep 2023 05:37:37 -0400 Subject: [PATCH 2/3] [ticket/17188] Add unit tests Adds rxu's unit tests, with rubencm's fix PHPBB3-17188 --- tests/request/type_cast_helper_test.php | 105 +++++++++++++++++------- 1 file changed, 74 insertions(+), 31 deletions(-) diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index 5810c67b78..745008ec3a 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -20,43 +20,86 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $this->type_cast_helper = new \phpbb\request\type_cast_helper(); } - public function test_simple_recursive_set_var() + public function type_cast_helper_test_data() { - $data = 'eviL<3'; - $expected = 'eviL<3'; + return [ + [ + 'eviL<3', + 'eviL<3', + '', + true, + ], + [ + ['eviL<3'], + ['eviL<3'], + [0 => ''], + true, + ], + [ + " eviL<3\t\t", + " eviL<3\t\t", + '', + true, + false, + ], + [ + [" eviL<3\t\t"], + [" eviL<3\t\t"], + [0 => ''], + true, + false, + ], + // Test multiline unicode vars + [ + " - $this->type_cast_helper->recursive_set_var($data, '', true); +Тест ", + " - $this->assertEquals($expected, $data); +Тест ", + '', + true, + false, + ], + [ + " + +Тест ", + "Тест", + '', + true, + true, + ], + [ + [" + +Тест "], + [" + +Тест "], + [0 => ''], + true, + false, + ], + [ + [" + +Тест "], + ["Тест"], + [0 => ''], + true, + true, + ], + ]; } - public function test_nested_recursive_set_var() + /** + * @dataProvider type_cast_helper_test_data + */ + public function test_recursive_set_var($var, $expected, $default, $multibyte, $trim = true) { - $data = array('eviL<3'); - $expected = array('eviL<3'); + $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $trim); - $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true); - - $this->assertEquals($expected, $data); - } - - public function test_simple_untrimmed_recursive_set_var() - { - $data = " eviL<3\t\t"; - $expected = " eviL<3\t\t"; - - $this->type_cast_helper->recursive_set_var($data, '', true, false); - - $this->assertEquals($expected, $data); - } - - public function test_nested_untrimmed_recursive_set_var() - { - $data = array(" eviL<3\t\t"); - $expected = array(" eviL<3\t\t"); - - $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true, false); - - $this->assertEquals($expected, $data); + $this->assertEquals($expected, $var); } } From d4e0840e6f659a0782ad00e6fa51c00f715ca4b6 Mon Sep 17 00:00:00 2001 From: toxyy Date: Thu, 5 Oct 2023 16:16:30 -0400 Subject: [PATCH 3/3] [ticket/17188] Change regex being edited Change the edited regex to ruben's recommendation PHPBB3-17188 --- phpBB/phpbb/request/type_cast_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/request/type_cast_helper.php b/phpBB/phpbb/request/type_cast_helper.php index ff81b7130f..796ffd3d3f 100644 --- a/phpBB/phpbb/request/type_cast_helper.php +++ b/phpBB/phpbb/request/type_cast_helper.php @@ -55,7 +55,7 @@ class type_cast_helper implements \phpbb\request\type_cast_helper_interface // Make sure multibyte characters are wellformed if ($multibyte) { - if (!preg_match('/^./um', $result)) + if (!preg_match('//u', $result)) { $result = ''; }