Skip to content

Commit

Permalink
Improve handling of empty values in adm_config_set.php
Browse files Browse the repository at this point in the history
When processing an empty value, the code now evaluates the config type
as if user had selected 'default'; this ensures the proper case of
'empty' is used depending on the config being set (i.e. 0, '').

We also avoid calling the config parser in this case, because a simple
typecast is sufficient to process user input.

Fixes #21124
  • Loading branch information
dregad committed Jul 3, 2016
1 parent 9636642 commit b1173d8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions adm_config_set.php
Expand Up @@ -90,7 +90,8 @@


# For 'default', behavior is based on the global variable's type
if( $f_type == CONFIG_TYPE_DEFAULT ) {
# If value is empty, process as per default to ensure proper typecast
if( $f_type == CONFIG_TYPE_DEFAULT || empty( $f_value ) ) {
$t_config_global_value = config_get_global( $f_config_option );
if( is_string( $t_config_global_value ) ) {
$t_type = CONFIG_TYPE_STRING;
Expand All @@ -108,13 +109,15 @@
}

# Parse the value
if( $t_type == CONFIG_TYPE_STRING ) {
# Return strings as is
$t_value = $f_value;
} else {
# - Strings are returned as-is
# - Empty values are typecast as appropriate
$t_value = $f_value;
if( $t_type != CONFIG_TYPE_STRING ) {
try {
$t_parser = new ConfigParser( $f_value );
$t_value = $t_parser->parse( ConfigParser::EXTRA_TOKENS_IGNORE );
if( !empty( $f_value ) ) {
$t_parser = new ConfigParser( $f_value );
$t_value = $t_parser->parse( ConfigParser::EXTRA_TOKENS_IGNORE );
}

switch( $t_type ) {
case CONFIG_TYPE_INT:
Expand Down

0 comments on commit b1173d8

Please sign in to comment.