1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 00:02:18 +02:00

[ticket/16526] Correctly handle ACP CSV settings

PHPBB3-16526
This commit is contained in:
rxu 2020-06-11 21:46:05 +07:00
parent 8bb9a9803b
commit bb20f3966f
No known key found for this signature in database
GPG Key ID: 955F0567380E586A
4 changed files with 31 additions and 2 deletions

View File

@ -193,7 +193,7 @@ class acp_board
'allow_post_flash' => array('lang' => 'ALLOW_POST_FLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'allow_smilies' => array('lang' => 'ALLOW_SMILIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
'allow_post_links' => array('lang' => 'ALLOW_POST_LINKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'allowed_schemes_links' => array('lang' => 'ALLOWED_SCHEMES_LINKS', 'validate' => 'string', 'type' => 'text:0:255', 'explain' => true),
'allowed_schemes_links' => array('lang' => 'ALLOWED_SCHEMES_LINKS', 'validate' => 'csv', 'type' => 'text:0:255', 'explain' => true),
'allow_nocensors' => array('lang' => 'ALLOW_NO_CENSORS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'allow_bookmarks' => array('lang' => 'ALLOW_BOOKMARKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'enable_post_confirm' => array('lang' => 'VISUAL_CONFIRM_POST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
@ -497,6 +497,19 @@ class acp_board
$cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => ''), true) : $this->new_config;
$error = array();
// Prevalidate allowed URL schemes
if ($mode == 'post')
{
$schemes = array_filter(explode(',', $cfg_array['allowed_schemes_links']));
foreach ($schemes as $scheme)
{
if (!preg_match('#^[a-z][a-z0-9+\\-.]*$#Di', $scheme))
{
$error[] = $language->lang('URL_SCHEME_INVALID', $language->lang('ALLOWED_SCHEMES_LINKS'), $scheme);
}
}
}
// We validate the complete config if wished
validate_config_vars($display_vars['vars'], $cfg_array, $error);

View File

@ -453,8 +453,20 @@ function validate_config_vars($config_vars, &$cfg_array, &$error)
$error[] = $language->lang('URL_INVALID', $language->lang($config_definition['lang']));
}
goto validate_string;
case 'csv':
// Validate comma separated values
$unfiltered_array = explode(',', $cfg_array[$config_name]);
$filtered_array = array_filter($unfiltered_array);
if (!empty($filtered_array) && count($unfiltered_array) !== count($filtered_array))
{
$error[] = $language->lang('CSV_INVALID', $language->lang($config_definition['lang']));
}
// no break here
validate_string:
case 'string':
$length = utf8_strlen($cfg_array[$config_name]);

View File

@ -235,6 +235,7 @@ $lang = array_merge($lang, array(
'CRON_NO_SUCH_TASK' => 'Could not find cron task “%s”.',
'CRON_NO_TASK' => 'No cron tasks need to be run right now.',
'CRON_NO_TASKS' => 'No cron tasks could be found.',
'CSV_INVALID' => 'The provided comma-separated setting “%1$s” is invalid. The values should be delimited by comma only, it should not contain any leading or trailing delimiters.',
'CURRENT_VERSION' => 'Current version',
'DEACTIVATE' => 'Deactivate',
@ -316,6 +317,7 @@ $lang = array_merge($lang, array(
'UCP' => 'User Control Panel',
'URL_INVALID' => 'The provided URL for the setting “%1$s” is invalid.',
'URL_SCHEME_INVALID' => 'The provided scheme “%2$s” in comma-separated setting “%1$s” is invalid. Scheme should start with a latin character followed by alphanumeric characters, hyphens or dots.',
'USERNAMES_EXPLAIN' => 'Place each username on a separate line.',
'USER_CONTROL_PANEL' => 'User Control Panel',

View File

@ -218,7 +218,9 @@ class factory implements \phpbb\textformatter\cache_interface
{
$configurator->urlConfig->disallowScheme($scheme);
}
foreach (array_filter(explode(',', $this->config['allowed_schemes_links'])) as $scheme)
$schemes = array_filter(explode(',', $this->config['allowed_schemes_links']));
foreach ($schemes as $scheme)
{
$configurator->urlConfig->allowScheme(trim($scheme));
}