aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2013-05-14 22:39:33 +0200
committerMarc Alexander <admin@m-a-styles.de>2013-05-14 22:39:33 +0200
commitdeefe5c0e48534cea1327cf685255d109d9d7e2c (patch)
tree40c4fa50563626043ebbcefde191ab92d8f1b54c
parent1fae7720e43c8ff853225e16d0de54395d9ab051 (diff)
downloadforums-deefe5c0e48534cea1327cf685255d109d9d7e2c.tar
forums-deefe5c0e48534cea1327cf685255d109d9d7e2c.tar.gz
forums-deefe5c0e48534cea1327cf685255d109d9d7e2c.tar.bz2
forums-deefe5c0e48534cea1327cf685255d109d9d7e2c.tar.xz
forums-deefe5c0e48534cea1327cf685255d109d9d7e2c.zip
[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
-rw-r--r--phpBB/includes/acp/acp_groups.php7
-rw-r--r--phpBB/includes/ucp/ucp_groups.php15
-rw-r--r--phpBB/language/en/common.php2
-rw-r--r--phpBB/styles/prosilver/template/ucp_groups_manage.html2
-rw-r--r--tests/functional/ucp_groups_test.php15
5 files changed, 20 insertions, 21 deletions
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php
index beb7aefee5..3b0d53d52c 100644
--- a/phpBB/includes/acp/acp_groups.php
+++ b/phpBB/includes/acp/acp_groups.php
@@ -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
diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php
index 8ff76eac42..bf6af8b6f1 100644
--- a/phpBB/includes/ucp/ucp_groups.php
+++ b/phpBB/includes/ucp/ucp_groups.php
@@ -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))
diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php
index 129deb551c..c986e8213d 100644
--- a/phpBB/language/en/common.php
+++ b/phpBB/language/en/common.php
@@ -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.',
diff --git a/phpBB/styles/prosilver/template/ucp_groups_manage.html b/phpBB/styles/prosilver/template/ucp_groups_manage.html
index 87b548c23b..d15cca8ee8 100644
--- a/phpBB/styles/prosilver/template/ucp_groups_manage.html
+++ b/phpBB/styles/prosilver/template/ucp_groups_manage.html
@@ -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>
diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php
index d5ac6f697e..7a315c2018 100644
--- a/tests/functional/ucp_groups_test.php
+++ b/tests/functional/ucp_groups_test.php
@@ -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'),
);
}