Throw warning if invalid internal_encoding ini is specified

This commit is contained in:
Nikita Popov 2020-05-07 14:43:36 +02:00
parent 98acdbff18
commit 481b7421f3
12 changed files with 34 additions and 31 deletions

View File

@ -898,6 +898,10 @@ static int _php_mb_ini_mbstring_internal_encoding_set(const char *new_value, siz
if (!new_value || !new_value_length || !(encoding = mbfl_name2encoding(new_value))) {
/* falls back to UTF-8 if an unknown encoding name is given */
if (new_value) {
php_error_docref("ref.mbstring", E_WARNING,
"Unknown encoding \"%s\" in ini setting", new_value);
}
encoding = mbfl_no2encoding(mbfl_no_encoding_utf8);
}
MBSTRG(internal_encoding) = encoding;

View File

@ -23,6 +23,7 @@ PHP Deprecated: PHP Startup: Use of mbstring.http_input is deprecated in Unknow
PHP Warning: PHP Startup: INI setting contains invalid encoding "HTTP_INPUT" in Unknown on line 0
PHP Deprecated: PHP Startup: Use of mbstring.http_output is deprecated in Unknown on line 0
PHP Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0
PHP Warning: PHP Startup: Unknown encoding "UNKNOWN_ENCODING" in ini setting in Unknown on line 0
Warning: PHP Startup: INI setting contains invalid encoding "DETECT_ORDER" in Unknown on line 0
@ -33,3 +34,5 @@ Warning: PHP Startup: INI setting contains invalid encoding "HTTP_INPUT" in Unkn
Deprecated: PHP Startup: Use of mbstring.http_output is deprecated in Unknown on line 0
Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0
Warning: PHP Startup: Unknown encoding "UNKNOWN_ENCODING" in ini setting in Unknown on line 0

View File

@ -21,8 +21,11 @@ echo ini_get('mbstring.internal_encoding')."\n";
?>
--EXPECT--
PHP Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0
PHP Warning: PHP Startup: Unknown encoding "BAD" in ini setting in Unknown on line 0
Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0
Warning: PHP Startup: Unknown encoding "BAD" in ini setting in Unknown on line 0
*** Testing INI mbstring.internal_encoding: invalid encoding specified in INI ***
UTF-8
BAD

View File

@ -386,10 +386,7 @@ static enum entity_charset determine_charset(char *charset_hint)
if (zenc != NULL) {
charset_hint = (char *)zend_multibyte_get_encoding_name(zenc);
if (charset_hint != NULL && (len=strlen(charset_hint)) != 0) {
if ((len == 4) /* sizeof (auto|pass) */ &&
/* XXX should the "wchar" be ignored as well?? */
(!memcmp("pass", charset_hint, 4) ||
!memcmp("auto", charset_hint, 4))) {
if (len == sizeof("auto")-1 && !memcmp("auto", charset_hint, sizeof("auto")-1)) {
charset_hint = NULL;
len = 0;
} else {

View File

@ -2,11 +2,10 @@
htmlentities() test 1 (cp1252)
--INI--
output_handler=
internal_encoding=pass
--FILE--
<?php
var_dump(htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, 'cp1252'));
var_dump(htmlentities("\x80\xa2\xa3\xa4\xa5", ENT_QUOTES, 'cp1252'));
var_dump(htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, 'cp1252'));
var_dump(htmlentities("\x80\xa2\xa3\xa4\xa5", ENT_QUOTES, 'cp1252'));
?>
--EXPECT--
string(28) "&sbquo;&dagger;&trade;&Yuml;"

View File

@ -10,11 +10,12 @@ if (!$result) {
--INI--
output_handler=
default_charset=
internal_encoding=pass
internal_encoding=
--FILE--
<?php
setlocale(LC_CTYPE, "fr_FR.ISO-8859-15", "fr_FR.ISO8859-15", 'fr_FR@euro');
var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, ''));
// Locale-based encoding guessing no longer works.
setlocale(LC_CTYPE, "fr_FR.ISO-8859-15", "fr_FR.ISO8859-15", 'fr_FR@euro');
var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, ''));
?>
--EXPECT--
string(20) "&OElig;&oelig;&Yuml;"
string(0) ""

View File

@ -10,11 +10,12 @@ if (!$result || preg_match('/ISO/i', setlocale(LC_CTYPE, 0)) == 0) {
--INI--
output_handler=
default_charset=
internal_encoding=pass
internal_encoding=
--FILE--
<?php
setlocale( LC_CTYPE, "de_DE.ISO-8859-1", "de_DE.ISO8859-1");
var_dump(htmlentities("\xe4\xf6\xfc", ENT_QUOTES, ''));
// Locale-based encoding guessing no longer works.
setlocale( LC_CTYPE, "de_DE.ISO-8859-1", "de_DE.ISO8859-1");
var_dump(htmlentities("\xe4\xf6\xfc", ENT_QUOTES));
?>
--EXPECT--
string(18) "&auml;&ouml;&uuml;"
string(0) ""

View File

@ -2,13 +2,12 @@
htmlentities() test 10 (default_charset / cp1252)
--INI--
output_handler=
internal_encoding=pass
default_charset=cp1252
--FILE--
<?php
print ini_get('default_charset')."\n";
var_dump(htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, ''));
var_dump(htmlentities("\x80\xa2\xa3\xa4\xa5", ENT_QUOTES, ''));
print ini_get('default_charset')."\n";
var_dump(htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, ''));
var_dump(htmlentities("\x80\xa2\xa3\xa4\xa5", ENT_QUOTES, ''));
?>
--EXPECT--
cp1252

View File

@ -2,12 +2,11 @@
htmlentities() test 11 (default_charset / ISO-8859-15)
--INI--
output_handler=
internal_encoding=pass
default_charset=ISO-8859-15
--FILE--
<?php
print ini_get('default_charset')."\n";
var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, ''));
print ini_get('default_charset')."\n";
var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, ''));
?>
--EXPECT--
ISO-8859-15

View File

@ -2,12 +2,11 @@
htmlentities() test 12 (default_charset / ISO-8859-1)
--INI--
output_handler=
internal_encoding=pass
default_charset=ISO-8859-1
--FILE--
<?php
print ini_get('default_charset')."\n";
var_dump(htmlentities("\xe4\xf6\xfc", ENT_QUOTES, ''));
print ini_get('default_charset')."\n";
var_dump(htmlentities("\xe4\xf6\xfc", ENT_QUOTES, ''));
?>
--EXPECT--
ISO-8859-1

View File

@ -2,13 +2,12 @@
htmlentities() test 13 (default_charset / EUC-JP)
--INI--
output_handler=
internal_encoding=pass
default_charset=EUC-JP
filter.default=unsafe_raw
--FILE--
<?php
print ini_get('default_charset')."\n";
var_dump(htmlentities("\xa1\xa2\xa1\xa3\xa1\xa4", ENT_QUOTES, ''));
print ini_get('default_charset')."\n";
var_dump(htmlentities("\xa1\xa2\xa1\xa3\xa1\xa4", ENT_QUOTES, ''));
?>
--EXPECTF--
EUC-JP

View File

@ -2,13 +2,12 @@
htmlentities() test 14 (default_charset / Shift_JIS)
--INI--
output_handler=
internal_encoding=pass
default_charset=Shift_JIS
filter.default=unsafe_raw
--FILE--
<?php
print ini_get('default_charset')."\n";
var_dump(htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, ''));
print ini_get('default_charset')."\n";
var_dump(htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, ''));
?>
--EXPECTF--
Shift_JIS