From 1276d2fdf3f08842334fa1d393eccc8d9a8e4edf Mon Sep 17 00:00:00 2001 From: EA117 Date: Thu, 25 Feb 2021 09:30:19 -0600 Subject: [PATCH 1/2] [ticket/16708] Update the UTF-8 check for multiple encoding settings Update the mbstring.http_input and mbstring.http_output configuration check, from being the deprecated PHP 5.6.x "PASS, or blank" to now be "UTF-8, or blank". PHP documentation specifies this configuration should be left blank, in order to inherit default_charset, which phpBB requires to be configured as UTF-8. For a phpBB customer where mbstring.http_input and mbstring.http_output is set to UTF-8 rather than being left blank, and is a shared hosting configuration that the customer isn't permitted to change, the phpBB ACP warning that "your http_input/http_output configuration is invalid" isn't helpful. Their setting is UTF-8, which is the encoding http_input/http_output would be using if it had been left blank and allowed to inherit default_charset. Our "warning" isn't advising the user of a misconfiguration which is causing a phpBB functionality problem. phpBB is getting exactly the UTF-8 encoding it was intending to get; same as when it was checking whether the setting was left blank, too. Also update the default_charset test to permit "UTF-8, or blank". This had been correctly changed to effectively test "UTF-8, or NULL" during PHPBB3-16698, based on code inspection of /vendor/bantu/ini-get-wrapper/src/IniGetWrapper.php which confirmed IniGetWrapper::getString() will return NULL for any setting which does not exist. However, testing on some PHP platforms shows PHP itself returning an empty string for a parameter which isn't defined in the PHP.INI, and so we receive an empty string instead of NULL. So the test was updated so that we effectively check for "UTF-8, or blank, or NULL", all of which result in UTF-8 being used. PHPBB3-16708 --- phpBB/includes/acp/acp_main.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 3c27b68ac2..265c7efbd5 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -702,9 +702,9 @@ class acp_main 'S_MBSTRING_LOADED' => true, 'S_MBSTRING_FUNC_OVERLOAD_FAIL' => $func_overload && ($func_overload & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING)), 'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => $encoding_translation && ($encoding_translation != 0), - 'S_MBSTRING_HTTP_INPUT_FAIL' => !empty($http_input), - 'S_MBSTRING_HTTP_OUTPUT_FAIL' => !empty($http_output), - 'S_DEFAULT_CHARSET_FAIL' => $default_charset !== null && strtolower($default_charset) !== 'utf-8', + 'S_MBSTRING_HTTP_INPUT_FAIL' => $http_input !== null && !in_array(strtolower($http_input), array('utf-8', '')), + 'S_MBSTRING_HTTP_OUTPUT_FAIL' => $http_output !== null && !in_array(strtolower($http_output), array('utf-8', '')), + 'S_DEFAULT_CHARSET_FAIL' => $default_charset !== null && !in_array(strtolower($default_charset), array('utf-8', '')), ]); } From 35ace5e38430868e1fc8996768c4d70db5e12bfc Mon Sep 17 00:00:00 2001 From: EA117 Date: Thu, 25 Feb 2021 11:55:08 -0600 Subject: [PATCH 2/2] [ticket/16708] Update the UTF-8 check for multiple encoding settings Fixed short array syntax, moved testing logic into member helper function. PHPBB3-16708 --- phpBB/includes/acp/acp_main.php | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 265c7efbd5..2f99c056e6 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -702,9 +702,9 @@ class acp_main 'S_MBSTRING_LOADED' => true, 'S_MBSTRING_FUNC_OVERLOAD_FAIL' => $func_overload && ($func_overload & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING)), 'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => $encoding_translation && ($encoding_translation != 0), - 'S_MBSTRING_HTTP_INPUT_FAIL' => $http_input !== null && !in_array(strtolower($http_input), array('utf-8', '')), - 'S_MBSTRING_HTTP_OUTPUT_FAIL' => $http_output !== null && !in_array(strtolower($http_output), array('utf-8', '')), - 'S_DEFAULT_CHARSET_FAIL' => $default_charset !== null && !in_array(strtolower($default_charset), array('utf-8', '')), + 'S_MBSTRING_HTTP_INPUT_FAIL' => $this->warn_if_not_utf8($http_input), + 'S_MBSTRING_HTTP_OUTPUT_FAIL' => $this->warn_if_not_utf8($http_output), + 'S_DEFAULT_CHARSET_FAIL' => $this->warn_if_not_utf8($default_charset), ]); } @@ -717,4 +717,34 @@ class acp_main $this->tpl_name = 'acp_main'; $this->page_title = 'ACP_MAIN'; } + + /** + * Wrapper for checking IniGetWrapper::getString return value for "effectively UTF-8". + * + * Since PHP 5.6.x, PHP wants mbstring.http_input and mbstring.http_output to be blank, + * so that they will inherit default_charset. IniGetWrapper::getString itself returns + * NULL if a setting did not exist. But we can also see PHP itself return an empty string + * when the PHP.INI contains no reference to one of these settings. + * + * So we're going to account for three cases here, and consider that "all of them mean + * we're about to get the UTF-8 encoding behavior that phpBB requires." First is for + * either NULL or an empty string, either of which would represent a system configured + * per PHP documentation to "leave this setting blank." + * + * But we will also accept "UTF-8" or "utf-8". Not just because this is explicitly required + * for checking default_charset, but also because if either mbstring.http_input or + * mbstring.http_output were explicitly configured to this, phpBB is still getting the + * "PHP will use UTF-8" behavior intended. Creating a warning "just because they didn't + * get there with a blank value" doesn't make things better, and may not be a setting + * that the user can change in order to eliminate the unnecessary warning. + * + * @param string $config Value returned from IniGetWrapper::getString() to be examined. + * + * @return bool True (warning should be presented) if the configuration value + * was not effecitvely "UTF-8". Else false (no warning to be shown). + */ + function warn_if_not_utf8($config) + { + return ($config !== null) && (!in_array(strtolower($config), ['utf-8', ''])); + } }