mirror of
https://github.com/php/php-src.git
synced 2026-04-27 10:16:41 +02:00
Merge branch 'PHP-5.6'
* PHP-5.6: Remove unneeded string copy. Allow to set ''(empty string values) internal/input/output_encoding for better compatibility. i.e. Runtime INI value changes. More compliance to the RFC. Improve/add encoding handling tests. i.e. Rather than set encoding automagic way, detect it.
This commit is contained in:
+60
-38
@@ -226,14 +226,10 @@ static PHP_INI_MH(OnUpdateInputEncoding)
|
||||
if (new_value_length >= ICONV_CSNMAXLEN) {
|
||||
return FAILURE;
|
||||
}
|
||||
if (new_value_length) {
|
||||
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
|
||||
php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.input_encoding is deprecated");
|
||||
}
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
} else {
|
||||
OnUpdateString(entry, PG(input_encoding), strlen(PG(input_encoding))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
|
||||
php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.input_encoding is deprecated");
|
||||
}
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -243,14 +239,10 @@ static PHP_INI_MH(OnUpdateOutputEncoding)
|
||||
if(new_value_length >= ICONV_CSNMAXLEN) {
|
||||
return FAILURE;
|
||||
}
|
||||
if (new_value_length) {
|
||||
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
|
||||
php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.output_encoding is deprecated");
|
||||
}
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
} else {
|
||||
OnUpdateString(entry, PG(output_encoding), strlen(PG(output_encoding))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
|
||||
php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.output_encoding is deprecated");
|
||||
}
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -260,14 +252,10 @@ static PHP_INI_MH(OnUpdateInternalEncoding)
|
||||
if(new_value_length >= ICONV_CSNMAXLEN) {
|
||||
return FAILURE;
|
||||
}
|
||||
if (new_value_length) {
|
||||
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
|
||||
php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.internal_encoding is deprecated");
|
||||
}
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
} else {
|
||||
OnUpdateString(entry, PG(internal_encoding), strlen(PG(internal_encoding))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
|
||||
php_error_docref("ref.iconv" TSRMLS_CC, E_DEPRECATED, "Use of iconv.internal_encoding is deprecated");
|
||||
}
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -356,6 +344,40 @@ PHP_MINFO_FUNCTION(miconv)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static char *get_internal_encoding(TSRMLS_D) {
|
||||
if (ICONVG(internal_encoding) && ICONVG(internal_encoding)[0]) {
|
||||
return ICONVG(internal_encoding);
|
||||
} else if (PG(internal_encoding) && PG(internal_encoding)[0]) {
|
||||
return PG(internal_encoding);
|
||||
} else if (SG(default_charset)) {
|
||||
return SG(default_charset);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static char *get_input_encoding(TSRMLS_D) {
|
||||
if (ICONVG(input_encoding) && ICONVG(input_encoding)[0]) {
|
||||
return ICONVG(input_encoding);
|
||||
} else if (PG(input_encoding) && PG(input_encoding)[0]) {
|
||||
return PG(input_encoding);
|
||||
} else if (SG(default_charset)) {
|
||||
return SG(default_charset);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static char *get_output_encoding(TSRMLS_D) {
|
||||
if (ICONVG(output_encoding) && ICONVG(output_encoding)[0]) {
|
||||
return ICONVG(output_encoding);
|
||||
} else if (PG(output_encoding) && PG(output_encoding)[0]) {
|
||||
return PG(output_encoding);
|
||||
} else if (SG(default_charset)) {
|
||||
return SG(default_charset);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC)
|
||||
{
|
||||
if (php_output_get_level(TSRMLS_C)) {
|
||||
@@ -397,12 +419,12 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
|
||||
|
||||
if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
|
||||
int len;
|
||||
char *p = strstr(ICONVG(output_encoding), "//");
|
||||
char *p = strstr(get_output_encoding(TSRMLS_C), "//");
|
||||
|
||||
if (p) {
|
||||
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int)(p - ICONVG(output_encoding)), ICONVG(output_encoding));
|
||||
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int)(p - get_output_encoding(TSRMLS_C)), get_output_encoding(TSRMLS_C));
|
||||
} else {
|
||||
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, ICONVG(output_encoding));
|
||||
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, get_output_encoding(TSRMLS_C));
|
||||
}
|
||||
if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) {
|
||||
SG(sapi_headers).send_default_content_type = 0;
|
||||
@@ -413,7 +435,7 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
|
||||
|
||||
if (output_context->in.used) {
|
||||
output_context->out.free = 1;
|
||||
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, ICONVG(output_encoding), ICONVG(internal_encoding)), ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC);
|
||||
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, get_output_encoding(TSRMLS_C), get_internal_encoding(TSRMLS_C)), get_output_encoding(TSRMLS_C), get_internal_encoding(TSRMLS_C) TSRMLS_CC);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
@@ -2000,7 +2022,7 @@ static void _php_iconv_show_error(php_iconv_err_t err, const char *out_charset,
|
||||
Returns the character count of str */
|
||||
PHP_FUNCTION(iconv_strlen)
|
||||
{
|
||||
char *charset = ICONVG(internal_encoding);
|
||||
char *charset = get_internal_encoding(TSRMLS_C);
|
||||
int charset_len = 0;
|
||||
char *str;
|
||||
int str_len;
|
||||
@@ -2033,7 +2055,7 @@ PHP_FUNCTION(iconv_strlen)
|
||||
Returns specified part of a string */
|
||||
PHP_FUNCTION(iconv_substr)
|
||||
{
|
||||
char *charset = ICONVG(internal_encoding);
|
||||
char *charset = get_internal_encoding(TSRMLS_C);
|
||||
int charset_len = 0;
|
||||
char *str;
|
||||
int str_len;
|
||||
@@ -2073,7 +2095,7 @@ PHP_FUNCTION(iconv_substr)
|
||||
Finds position of first occurrence of needle within part of haystack beginning with offset */
|
||||
PHP_FUNCTION(iconv_strpos)
|
||||
{
|
||||
char *charset = ICONVG(internal_encoding);
|
||||
char *charset = get_internal_encoding(TSRMLS_C);
|
||||
int charset_len = 0;
|
||||
char *haystk;
|
||||
int haystk_len;
|
||||
@@ -2121,7 +2143,7 @@ PHP_FUNCTION(iconv_strpos)
|
||||
Finds position of last occurrence of needle within part of haystack beginning with offset */
|
||||
PHP_FUNCTION(iconv_strrpos)
|
||||
{
|
||||
char *charset = ICONVG(internal_encoding);
|
||||
char *charset = get_internal_encoding(TSRMLS_C);
|
||||
int charset_len = 0;
|
||||
char *haystk;
|
||||
int haystk_len;
|
||||
@@ -2172,7 +2194,7 @@ PHP_FUNCTION(iconv_mime_encode)
|
||||
smart_str retval = {0};
|
||||
php_iconv_err_t err;
|
||||
|
||||
const char *in_charset = ICONVG(internal_encoding);
|
||||
const char *in_charset = get_internal_encoding(TSRMLS_C);
|
||||
const char *out_charset = in_charset;
|
||||
long line_len = 76;
|
||||
const char *lfchars = "\r\n";
|
||||
@@ -2285,7 +2307,7 @@ PHP_FUNCTION(iconv_mime_decode)
|
||||
{
|
||||
char *encoded_str;
|
||||
int encoded_str_len;
|
||||
char *charset = ICONVG(internal_encoding);
|
||||
char *charset = get_internal_encoding(TSRMLS_C);
|
||||
int charset_len = 0;
|
||||
long mode = 0;
|
||||
|
||||
@@ -2326,7 +2348,7 @@ PHP_FUNCTION(iconv_mime_decode_headers)
|
||||
{
|
||||
const char *encoded_str;
|
||||
int encoded_str_len;
|
||||
char *charset = ICONVG(internal_encoding);
|
||||
char *charset = get_internal_encoding(TSRMLS_C);
|
||||
int charset_len = 0;
|
||||
long mode = 0;
|
||||
|
||||
@@ -2494,15 +2516,15 @@ PHP_FUNCTION(iconv_get_encoding)
|
||||
|
||||
if (!strcasecmp("all", type)) {
|
||||
array_init(return_value);
|
||||
add_assoc_string(return_value, "input_encoding", ICONVG(input_encoding), 1);
|
||||
add_assoc_string(return_value, "output_encoding", ICONVG(output_encoding), 1);
|
||||
add_assoc_string(return_value, "internal_encoding", ICONVG(internal_encoding), 1);
|
||||
add_assoc_string(return_value, "input_encoding", get_input_encoding(TSRMLS_C), 1);
|
||||
add_assoc_string(return_value, "output_encoding", get_output_encoding(TSRMLS_C), 1);
|
||||
add_assoc_string(return_value, "internal_encoding", get_internal_encoding(TSRMLS_C), 1);
|
||||
} else if (!strcasecmp("input_encoding", type)) {
|
||||
RETVAL_STRING(ICONVG(input_encoding), 1);
|
||||
RETVAL_STRING(get_input_encoding(TSRMLS_C), 1);
|
||||
} else if (!strcasecmp("output_encoding", type)) {
|
||||
RETVAL_STRING(ICONVG(output_encoding), 1);
|
||||
RETVAL_STRING(get_output_encoding(TSRMLS_C), 1);
|
||||
} else if (!strcasecmp("internal_encoding", type)) {
|
||||
RETVAL_STRING(ICONVG(internal_encoding), 1);
|
||||
RETVAL_STRING(get_internal_encoding(TSRMLS_C), 1);
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
--TEST--
|
||||
Test default_charset handling
|
||||
--SKIPIF--
|
||||
<?php
|
||||
extension_loaded('iconv') or die('skip');
|
||||
function_exists('iconv_get_encoding') or die("skip iconv_get_encoding() is not available in this build");
|
||||
?>
|
||||
--INI--
|
||||
error_reporting=E_ALL & ~E_DEPRECATED
|
||||
default_charset=UTF-8
|
||||
internal_encoding=
|
||||
input_encoding=
|
||||
output_encoding=
|
||||
iconv.internal_encoding=
|
||||
iconv.input_encoding=
|
||||
iconv.output_encoding=
|
||||
--FILE--
|
||||
<?php
|
||||
echo "*** Testing default_charset handling ***\n";
|
||||
|
||||
echo "--- Get php.ini values ---\n";
|
||||
var_dump(ini_get('default_charset'),
|
||||
ini_get('internal_encoding'),
|
||||
ini_get('input_encoding'),
|
||||
ini_get('output_encoding'),
|
||||
ini_get('iconv.internal_encoding'),
|
||||
ini_get('iconv.input_encoding'),
|
||||
ini_get('iconv.output_encoding'));
|
||||
|
||||
echo "\n--- Altering encodings ---\n";
|
||||
var_dump(ini_set('default_charset', 'ISO-8859-1'));
|
||||
|
||||
echo "\n--- results of alterations ---\n";
|
||||
var_dump(ini_get('default_charset'),
|
||||
ini_get('internal_encoding'),
|
||||
ini_get('input_encoding'),
|
||||
ini_get('output_encoding'),
|
||||
ini_get('iconv.internal_encoding'),
|
||||
ini_get('iconv.input_encoding'),
|
||||
ini_get('iconv.output_encoding'));
|
||||
|
||||
/*
|
||||
echo "\n--- Altering encodings ---\n";
|
||||
var_dump(ini_set('default_charset', 'ISO-8859-1'),
|
||||
ini_set('internal_encoding'),
|
||||
ini_set('input_encoding'),
|
||||
ini_set('output_encoding'),
|
||||
ini_set('iconv.internal_encoding'),
|
||||
ini_set('iconv.input_encoding'),
|
||||
ini_set('iconv.output_encoding'));
|
||||
*/
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing default_charset handling ***
|
||||
--- Get php.ini values ---
|
||||
string(5) "UTF-8"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
|
||||
--- Altering encodings ---
|
||||
string(5) "UTF-8"
|
||||
|
||||
--- results of alterations ---
|
||||
string(10) "ISO-8859-1"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
Done
|
||||
+32
-4
@@ -601,6 +601,34 @@ static sapi_post_entry php_post_entries[] = {
|
||||
ZEND_GET_MODULE(mbstring)
|
||||
#endif
|
||||
|
||||
static char *get_internal_encoding(TSRMLS_D) {
|
||||
if (PG(internal_encoding) && PG(internal_encoding)[0]) {
|
||||
return PG(internal_encoding);
|
||||
} else if (SG(default_charset)) {
|
||||
return SG(default_charset);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static char *get_input_encoding(TSRMLS_D) {
|
||||
if (PG(input_encoding) && PG(input_encoding)[0]) {
|
||||
return PG(input_encoding);
|
||||
} else if (SG(default_charset)) {
|
||||
return SG(default_charset);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static char *get_output_encoding(TSRMLS_D) {
|
||||
if (PG(output_encoding) && PG(output_encoding)[0]) {
|
||||
return PG(output_encoding);
|
||||
} else if (SG(default_charset)) {
|
||||
return SG(default_charset);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/* {{{ allocators */
|
||||
static void *_php_mb_allocators_malloc(unsigned int sz)
|
||||
{
|
||||
@@ -1236,9 +1264,9 @@ static PHP_INI_MH(OnUpdate_mbstring_http_input)
|
||||
if (MBSTRG(http_input_list)) {
|
||||
pefree(MBSTRG(http_input_list), 1);
|
||||
}
|
||||
if (SUCCESS == php_mb_parse_encoding_list(PG(input_encoding), strlen(PG(input_encoding))+1, &list, &size, 1 TSRMLS_CC)) {
|
||||
if (SUCCESS == php_mb_parse_encoding_list(get_input_encoding(TSRMLS_C), strlen(get_input_encoding(TSRMLS_C))+1, &list, &size, 1 TSRMLS_CC)) {
|
||||
MBSTRG(http_input_list) = list;
|
||||
MBSTRG(http_input_list_size) = 0;
|
||||
MBSTRG(http_input_list_size) = size;
|
||||
return SUCCESS;
|
||||
}
|
||||
MBSTRG(http_input_list) = NULL;
|
||||
@@ -1270,7 +1298,7 @@ static PHP_INI_MH(OnUpdate_mbstring_http_output)
|
||||
const mbfl_encoding *encoding;
|
||||
|
||||
if (new_value == NULL || new_value_length == 0) {
|
||||
encoding = mbfl_name2encoding(PG(output_encoding));
|
||||
encoding = mbfl_name2encoding(get_output_encoding(TSRMLS_C));
|
||||
if (!encoding) {
|
||||
MBSTRG(http_output_encoding) = &mbfl_encoding_pass;
|
||||
MBSTRG(current_http_output_encoding) = &mbfl_encoding_pass;
|
||||
@@ -1336,7 +1364,7 @@ static PHP_INI_MH(OnUpdate_mbstring_internal_encoding)
|
||||
if (new_value_length) {
|
||||
return _php_mb_ini_mbstring_internal_encoding_set(new_value, new_value_length TSRMLS_CC);
|
||||
} else {
|
||||
return _php_mb_ini_mbstring_internal_encoding_set(PG(internal_encoding), strlen(PG(internal_encoding))+1 TSRMLS_CC);
|
||||
return _php_mb_ini_mbstring_internal_encoding_set(get_internal_encoding(TSRMLS_C), strlen(get_internal_encoding(TSRMLS_C))+1 TSRMLS_CC);
|
||||
}
|
||||
} else {
|
||||
/* the corresponding mbstring globals needs to be set according to the
|
||||
|
||||
+14
-21
@@ -84,16 +84,15 @@
|
||||
#define sjis_lead(c) ((c) != 0x80 && (c) != 0xA0 && (c) < 0xFD)
|
||||
#define sjis_trail(c) ((c) >= 0x40 && (c) != 0x7F && (c) < 0xFD)
|
||||
|
||||
/* {{{ get_charset
|
||||
/* {{{ get_default_charset
|
||||
*/
|
||||
static void get_charset(char **charset, int *charset_len TSRMLS_DC) {
|
||||
static char *get_default_charset(TSRMLS_D) {
|
||||
if (PG(internal_encoding) && PG(internal_encoding)[0]) {
|
||||
*charset_len = strlen(PG(internal_encoding));
|
||||
*charset = estrndup(PG(internal_encoding), *charset_len);
|
||||
return PG(internal_encoding);
|
||||
} else if (SG(default_charset) && SG(default_charset)[0] ) {
|
||||
*charset_len = strlen(SG(default_charset));
|
||||
*charset = estrndup(SG(default_charset), *charset_len);
|
||||
return SG(default_charset);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -1445,7 +1444,7 @@ encode_amp:
|
||||
*/
|
||||
static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all)
|
||||
{
|
||||
char *str, *hint_charset = "";
|
||||
char *str, *hint_charset = NULL;
|
||||
int str_len, hint_charset_len = 0;
|
||||
size_t new_len;
|
||||
long flags = ENT_COMPAT;
|
||||
@@ -1456,13 +1455,10 @@ static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all)
|
||||
return;
|
||||
}
|
||||
|
||||
if (hint_charset_len) {
|
||||
replaced = php_escape_html_entities_ex(str, str_len, &new_len, all, (int) flags, hint_charset, double_encode TSRMLS_CC);
|
||||
} else {
|
||||
get_charset(&hint_charset, &hint_charset_len TSRMLS_CC);
|
||||
replaced = php_escape_html_entities_ex(str, str_len, &new_len, all, (int) flags, hint_charset, double_encode TSRMLS_CC);
|
||||
efree(hint_charset);
|
||||
if (!hint_charset) {
|
||||
hint_charset = get_default_charset(TSRMLS_C);
|
||||
}
|
||||
replaced = php_escape_html_entities_ex(str, str_len, &new_len, all, (int) flags, hint_charset, double_encode TSRMLS_CC);
|
||||
|
||||
RETVAL_STRINGL(replaced, (int)new_len, 0);
|
||||
}
|
||||
@@ -1524,8 +1520,8 @@ PHP_FUNCTION(htmlspecialchars_decode)
|
||||
Convert all HTML entities to their applicable characters */
|
||||
PHP_FUNCTION(html_entity_decode)
|
||||
{
|
||||
char *str, *hint_charset = "";
|
||||
int str_len, hint_charset_len = 0;
|
||||
char *str, *hint_charset = NULL;
|
||||
int str_len, hint_charset_len;
|
||||
size_t new_len = 0;
|
||||
long quote_style = ENT_COMPAT;
|
||||
char *replaced;
|
||||
@@ -1535,13 +1531,10 @@ PHP_FUNCTION(html_entity_decode)
|
||||
return;
|
||||
}
|
||||
|
||||
if (hint_charset_len) {
|
||||
replaced = php_unescape_html_entities(str, str_len, &new_len, 1 /*all*/, quote_style, hint_charset TSRMLS_CC);
|
||||
} else {
|
||||
get_charset(&hint_charset, &hint_charset_len TSRMLS_CC);
|
||||
replaced = php_unescape_html_entities(str, str_len, &new_len, 1 /*all*/, quote_style, hint_charset TSRMLS_CC);
|
||||
efree(hint_charset);
|
||||
if (!hint_charset) {
|
||||
hint_charset = get_default_charset(TSRMLS_C);
|
||||
}
|
||||
replaced = php_unescape_html_entities(str, str_len, &new_len, 1 /*all*/, quote_style, hint_charset TSRMLS_CC);
|
||||
|
||||
if (replaced) {
|
||||
RETURN_STRINGL(replaced, (int)new_len, 0);
|
||||
|
||||
@@ -3,21 +3,102 @@ default_charset and htmlentities/htmlspecialchars/html_entity_decode
|
||||
--INI--
|
||||
default_charset=UTF-8
|
||||
internal_encoding=
|
||||
input_encoding=
|
||||
output_encoding=
|
||||
--FILE--
|
||||
<?php
|
||||
ini_set('default_charset', 'cp1252');
|
||||
var_dump(ini_get('default_charset'), ini_get('internal_encoding'));
|
||||
echo "*** Default php.ini value ***\n";
|
||||
var_dump(ini_get('default_charset'),
|
||||
ini_get('internal_encoding'),
|
||||
ini_get('input_encoding'),
|
||||
ini_get('output_encoding')
|
||||
);
|
||||
|
||||
|
||||
echo "*** Runtime change of default_charset ***\n";
|
||||
var_dump(ini_set('default_charset', 'cp1252'));
|
||||
|
||||
echo "*** Test with updated default_charset ***\n";
|
||||
var_dump(ini_get('default_charset'),
|
||||
ini_get('internal_encoding'),
|
||||
ini_get('input_encoding'),
|
||||
ini_get('output_encoding')
|
||||
);
|
||||
|
||||
var_dump(htmlentities("\xA3", ENT_HTML5));
|
||||
var_dump(htmlentities("\xA3", ENT_HTML5, 'cp1252'));
|
||||
|
||||
var_dump(bin2hex(html_entity_decode("£", ENT_HTML5)));
|
||||
var_dump(bin2hex(html_entity_decode("£", ENT_HTML5, 'cp1252')));
|
||||
|
||||
// Set internal_encoding to empty and try again
|
||||
echo "*** Change internal_encoding to empty ***\n";
|
||||
var_dump(ini_set('internal_encoding', ''));
|
||||
var_dump(ini_get('default_charset'),
|
||||
ini_get('internal_encoding'),
|
||||
ini_get('input_encoding'),
|
||||
ini_get('output_encoding')
|
||||
);
|
||||
|
||||
var_dump(htmlentities("\xA3", ENT_HTML5));
|
||||
var_dump(htmlentities("\xA3", ENT_HTML5, 'cp1252'));
|
||||
var_dump(bin2hex(html_entity_decode("£", ENT_HTML5)));
|
||||
var_dump(bin2hex(html_entity_decode("£", ENT_HTML5, 'cp1252')));
|
||||
|
||||
echo "*** Update input/output_encoding ***\n";
|
||||
var_dump(ini_set('input_encoding', 'ISO-8859-1'));
|
||||
var_dump(ini_set('output_encoding', 'ISO-8859-1'));
|
||||
var_dump(ini_get('default_charset'),
|
||||
ini_get('internal_encoding'),
|
||||
ini_get('input_encoding'),
|
||||
ini_get('output_encoding')
|
||||
);
|
||||
|
||||
// Should not be affected
|
||||
var_dump(htmlentities("\xA3", ENT_HTML5));
|
||||
var_dump(htmlentities("\xA3", ENT_HTML5, 'cp1252'));
|
||||
var_dump(bin2hex(html_entity_decode("£", ENT_HTML5)));
|
||||
var_dump(bin2hex(html_entity_decode("£", ENT_HTML5, 'cp1252')));
|
||||
|
||||
echo "Done\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
*** Default php.ini value ***
|
||||
string(5) "UTF-8"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
*** Runtime change of default_charset ***
|
||||
string(5) "UTF-8"
|
||||
*** Test with updated default_charset ***
|
||||
string(6) "cp1252"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(7) "£"
|
||||
string(7) "£"
|
||||
string(2) "a3"
|
||||
string(2) "a3"
|
||||
*** Change internal_encoding to empty ***
|
||||
string(0) ""
|
||||
string(6) "cp1252"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(7) "£"
|
||||
string(7) "£"
|
||||
string(2) "a3"
|
||||
string(2) "a3"
|
||||
*** Update input/output_encoding ***
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
string(6) "cp1252"
|
||||
string(0) ""
|
||||
string(10) "ISO-8859-1"
|
||||
string(10) "ISO-8859-1"
|
||||
string(7) "£"
|
||||
string(7) "£"
|
||||
string(2) "a3"
|
||||
string(2) "a3"
|
||||
Done
|
||||
|
||||
+6
-6
@@ -419,7 +419,7 @@ static PHP_INI_DISP(display_errors_mode)
|
||||
*/
|
||||
static PHP_INI_MH(OnUpdateInternalEncoding)
|
||||
{
|
||||
if (new_value_length) {
|
||||
if (new_value) {
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
} else {
|
||||
OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
@@ -432,7 +432,7 @@ static PHP_INI_MH(OnUpdateInternalEncoding)
|
||||
*/
|
||||
static PHP_INI_MH(OnUpdateInputEncoding)
|
||||
{
|
||||
if (new_value_length) {
|
||||
if (new_value) {
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
} else {
|
||||
OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
@@ -445,7 +445,7 @@ static PHP_INI_MH(OnUpdateInputEncoding)
|
||||
*/
|
||||
static PHP_INI_MH(OnUpdateOutputEncoding)
|
||||
{
|
||||
if (new_value_length) {
|
||||
if (new_value) {
|
||||
OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
} else {
|
||||
OnUpdateString(entry, SG(default_charset), strlen(SG(default_charset))+1, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
@@ -563,9 +563,9 @@ PHP_INI_BEGIN()
|
||||
STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct, sapi_globals)
|
||||
STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct, sapi_globals)
|
||||
STD_PHP_INI_ENTRY("internal_encoding", "", PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("input_encoding", "", PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("output_encoding", "", PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
|
||||
|
||||
Reference in New Issue
Block a user