[ticket/11538] Simplify colour value check and remove support for '#'

The input length for the hex color is now limited to 6 characters and
the support for colors starting with a '#' has been dropped. The allowed
input length of 7 in prosilver seems to have been a relict from old ages
of phpBB3. In order to have proper support for correct checking of the
colour value, the new code was also ported to the ACP groups manage page.
The tests have been modified to reflect the changes to the behavior of
the color check. Tests for the ACP will follow.

PHPBB3-11538
This commit is contained in:
Marc Alexander 2013-05-14 22:39:33 +02:00
parent 1fae7720e4
commit deefe5c0e4
5 changed files with 20 additions and 21 deletions

View file

@ -422,6 +422,13 @@ class acp_groups
$error = array_merge($error, array_map(array(&$user, 'lang'), $max_recipients_error));
}
// Validate submitted colour value
if ($colour_error = validate_data($submit_ary, array('colour' => array('match', true, '/^([0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/'))))
{
// Replace "error" string with its real, localised form
$error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));
}
if (!sizeof($error))
{
// Only set the rank, colour, etc. if it's changed or if we're adding a new

View file

@ -595,18 +595,11 @@ class ucp_groups
$error[] = $user->lang['FORM_INVALID'];
}
if (!empty($submit_ary['colour']))
// Validate submitted colour value
if ($colour_error = validate_data($submit_ary, array('colour' => array('match', true, '/^([0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/'))))
{
preg_match('/^#?(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/', $submit_ary['colour'], $group_colour);
if (sizeof($group_colour))
{
$submit_ary['colour'] = (strpos($group_colour[0], '#') !== false) ? str_replace('#', '', $group_colour[0]) : $group_colour[0];
}
else
{
$error[] = $user->lang['COLOUR_INVALID'];
}
// Replace "error" string with its real, localised form
$error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));
}
if (!sizeof($error))

View file

@ -120,7 +120,6 @@ $lang = array_merge($lang, array(
'CLICK_VIEW_PRIVMSG' => '%sGo to your inbox%s',
'COLLAPSE_VIEW' => 'Collapse view',
'CLOSE_WINDOW' => 'Close window',
'COLOUR_INVALID' => 'The colour value you entered is invalid.',
'COLOUR_SWATCH' => 'Colour swatch',
'COMMA_SEPARATOR' => ', ', // Used in pagination of ACP & prosilver, use localised comma if appropriate, eg: Ideographic or Arabic
'CONFIRM' => 'Confirm',
@ -723,6 +722,7 @@ $lang = array_merge($lang, array(
'WHO_IS_ONLINE' => 'Who is online',
'WRONG_PASSWORD' => 'You entered an incorrect password.',
'WRONG_DATA_COLOUR' => 'The colour value you entered is invalid.',
'WRONG_DATA_ICQ' => 'The number you entered is not a valid ICQ number.',
'WRONG_DATA_JABBER' => 'The name you entered is not a valid Jabber account name.',
'WRONG_DATA_LANG' => 'The language you specified is not valid.',

View file

@ -55,7 +55,7 @@
<fieldset>
<dl>
<dt><label for="group_colour">{L_GROUP_COLOR}:</label><br /><span>{L_GROUP_COLOR_EXPLAIN}</span></dt>
<dd><input name="group_colour" type="text" id="group_colour" value="{GROUP_COLOUR}" size="7" maxlength="7" class="inputbox narrow" /> <span style="background-color: {GROUP_COLOUR};">&nbsp;&nbsp;&nbsp;</span> [ <a href="{U_SWATCH}" onclick="popup(this.href, 636, 150, '_swatch'); return false;">{L_COLOUR_SWATCH}</a> ]</dd>
<dd><input name="group_colour" type="text" id="group_colour" value="{GROUP_COLOUR}" size="6" maxlength="6" class="inputbox narrow" /> <span style="background-color: {GROUP_COLOUR};">&nbsp;&nbsp;&nbsp;</span> [ <a href="{U_SWATCH}" onclick="popup(this.href, 636, 150, '_swatch'); return false;">{L_COLOUR_SWATCH}</a> ]</dd>
</dl>
<dl>
<dt><label for="group_rank">{L_GROUP_RANK}:</label></dt>

View file

@ -15,15 +15,14 @@ class phpbb_functional_ucp_groups_test extends phpbb_functional_test_case
public function groups_manage_test_data()
{
return array(
array('#AA0000', 'GROUP_UPDATED'),
array('#AA0000', 'WRONG_DATA_COLOUR'),
array('AA0000', 'GROUP_UPDATED'),
array('AA0000v', 'COLOUR_INVALID'),
array('vAA0000', 'COLOUR_INVALID'),
array('AAG000', 'COLOUR_INVALID'),
array('#a00', 'GROUP_UPDATED'),
array('ag0', 'COLOUR_INVALID'),
array('#ag0', 'COLOUR_INVALID'),
array('##bcc', 'COLOUR_INVALID'),
array('AA0000v', 'WRONG_DATA_COLOUR'),
array('vAA0000', 'WRONG_DATA_COLOUR'),
array('AAG000','WRONG_DATA_COLOUR'),
array('a00', 'GROUP_UPDATED'),
array('ag0', 'WRONG_DATA_COLOUR'),
array('#aa0', 'WRONG_DATA_COLOUR'),
);
}