From cd1da92d8540d6b4aa0fa1ccf2bcafe68007288a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 19 May 2013 17:45:45 +0200 Subject: [PATCH] [ticket/11538] Add optional switch as argument to hex colour validation The value of $optional will decide whether an empty string will be treated as incorrect input or if it is allowed. The optional argument will default to false and therefore treat an empty string as incorrect unless explicitly told to not do so. PHPBB3-11538 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/functions_user.php | 8 +++++--- phpBB/includes/ucp/ucp_groups.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 089fe4baa1..83c355540e 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -421,7 +421,7 @@ class acp_groups */ $validation_checks = array( 'max_recipients' => array('num', false, 0, 16777215), - 'colour' => array('hex_colour'), + 'colour' => array('hex_colour', true), ); if ($validation_error = validate_data($submit_ary, $validation_checks)) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index f8e1fcaa45..61972c3876 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1903,14 +1903,16 @@ function validate_jabber($jid) * Validate hex colour value * * @param string $colour The hex colour value -* @return bool|string Error message if colour value is incorrect, false if it +* @param bool $optional Whether the colour value is optional. True if an empty +* string will be accepted as correct input, false if not. +* @return bool|string Error message if colour value is incorrect, false if it * fits the hex colour code */ -function phpbb_validate_hex_colour($colour) +function phpbb_validate_hex_colour($colour, $optional = false) { if (empty($colour)) { - return false; + return (($optional) ? false : 'WRONG_DATA'); } if (!preg_match('/^([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/', $colour)) diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 20a55d8c32..9365913541 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -596,7 +596,7 @@ class ucp_groups } // Validate submitted colour value - if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour')))) + if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour', true)))) { // Replace "error" string with its real, localised form $error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));