-
Notifications
You must be signed in to change notification settings - Fork 7.9k
PHP 5.6 RFC default encoding #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eae64db
Apply PoC patch
e6164f3
WIP mostly works
c13e733
Merge branch 'PHP-5.6' into PHP-5.6-rfc-default-encoding
516c19d
Remove hard coded ini default
971b1e0
Use NULL instead of ""
1f97e30
Update ini. Remove automagic internal encoding setting via language
cc4a3c0
Add tests
748e5cc
Fixed segfaults and test. How did I miss it...
bf21cce
It seems I have cli server testing. Just add required changes for def…
167400a
It seems I have cli server testing problem. Just add required changes…
4818292
It seems I have cli server testing problem. Just add required changes…
7dac172
More header fix
91629e5
Merge branch 'PHP-5.6' into PHP-5.6-rfc-default-encoding
c5c2703
More header fix
e75a9f0
Fixed broken test
b592dc6
More header fix. Should be the last one
ecb33c6
Fix php.ini-* comment
c566afa
Fix more INI comments
5eba9bf
Merge remote-tracking branch 'upstream/PHP-5.6' into PHP-5.6-rfc-defa…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--TEST-- | ||
Encoding INI test | ||
--SKIPIF-- | ||
<?php extension_loaded('iconv') or die('skip mbstring not available'); ?> | ||
--INI-- | ||
default_charset=ISO-8859-1 | ||
internal_encoding= | ||
input_encoding= | ||
output_encoding= | ||
iconv.internal_encoding=ISO-8859-1 | ||
iconv.http_input=ISO-8859-1 | ||
iconv.http_output=ISO-8859-1 | ||
--FILE-- | ||
<?php | ||
echo "Getting INI\n"; | ||
var_dump(ini_get('default_charset')); | ||
var_dump(ini_get('internal_encoding')); | ||
var_dump(ini_get('input_encoding')); | ||
var_dump(ini_get('output_encoding')); | ||
|
||
var_dump(ini_get('iconv.internal_encoding')); | ||
var_dump(ini_get('iconv.input_encoding')); | ||
var_dump(ini_get('iconv.output_encoding')); | ||
|
||
echo "Setting INI\n"; | ||
var_dump(ini_set('default_charset', 'UTF-8')); | ||
var_dump(ini_set('internal_encoding', 'UTF-8')); | ||
var_dump(ini_set('input_encoding', 'UTF-8')); | ||
var_dump(ini_set('output_encoding', 'UTF-8')); | ||
var_dump(ini_set('iconv.internal_encoding', 'UTF-8')); | ||
var_dump(ini_set('iconv.input_encoding', 'UTF-8')); | ||
var_dump(ini_set('iconv.output_encoding', 'UTF-8')); | ||
|
||
echo "Getting INI\n"; | ||
var_dump(ini_get('default_charset')); | ||
var_dump(ini_get('internal_encoding')); | ||
var_dump(ini_get('input_encoding')); | ||
var_dump(ini_get('output_encoding')); | ||
|
||
var_dump(ini_get('iconv.internal_encoding')); | ||
var_dump(ini_get('iconv.input_encoding')); | ||
var_dump(ini_get('iconv.output_encoding')); | ||
|
||
--EXPECT-- | ||
Getting INI | ||
string(10) "ISO-8859-1" | ||
string(0) "" | ||
string(0) "" | ||
string(0) "" | ||
string(10) "ISO-8859-1" | ||
string(0) "" | ||
string(0) "" | ||
Setting INI | ||
string(10) "ISO-8859-1" | ||
string(0) "" | ||
string(0) "" | ||
string(0) "" | ||
string(10) "ISO-8859-1" | ||
string(0) "" | ||
string(0) "" | ||
Getting INI | ||
string(5) "UTF-8" | ||
string(5) "UTF-8" | ||
string(5) "UTF-8" | ||
string(5) "UTF-8" | ||
string(5) "UTF-8" | ||
string(5) "UTF-8" | ||
string(5) "UTF-8" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1236,6 +1236,11 @@ 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)) { | ||
MBSTRG(http_input_list) = list; | ||
MBSTRG(http_input_list_size) = 0; | ||
return SUCCESS; | ||
} | ||
MBSTRG(http_input_list) = NULL; | ||
MBSTRG(http_input_list_size) = 0; | ||
return SUCCESS; | ||
|
@@ -1261,18 +1266,20 @@ static PHP_INI_MH(OnUpdate_mbstring_http_output) | |
const mbfl_encoding *encoding; | ||
|
||
if (new_value == NULL || new_value_length == 0) { | ||
MBSTRG(http_output_encoding) = &mbfl_encoding_pass; | ||
MBSTRG(current_http_output_encoding) = &mbfl_encoding_pass; | ||
return SUCCESS; | ||
} | ||
|
||
encoding = mbfl_name2encoding(new_value); | ||
if (!encoding) { | ||
MBSTRG(http_output_encoding) = &mbfl_encoding_pass; | ||
MBSTRG(current_http_output_encoding) = &mbfl_encoding_pass; | ||
return FAILURE; | ||
encoding = mbfl_name2encoding(PG(output_encoding)); | ||
if (!encoding) { | ||
MBSTRG(http_output_encoding) = &mbfl_encoding_pass; | ||
MBSTRG(current_http_output_encoding) = &mbfl_encoding_pass; | ||
return SUCCESS; | ||
} | ||
} else { | ||
encoding = mbfl_name2encoding(new_value); | ||
if (!encoding) { | ||
MBSTRG(http_output_encoding) = &mbfl_encoding_pass; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Save as above. |
||
MBSTRG(current_http_output_encoding) = &mbfl_encoding_pass; | ||
return FAILURE; | ||
} | ||
} | ||
|
||
MBSTRG(http_output_encoding) = encoding; | ||
MBSTRG(current_http_output_encoding) = encoding; | ||
return SUCCESS; | ||
|
@@ -1285,47 +1292,17 @@ int _php_mb_ini_mbstring_internal_encoding_set(const char *new_value, uint new_v | |
const mbfl_encoding *encoding; | ||
|
||
if (!new_value || new_value_length == 0 || !(encoding = mbfl_name2encoding(new_value))) { | ||
switch (MBSTRG(language)) { | ||
case mbfl_no_language_uni: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_utf8); | ||
break; | ||
case mbfl_no_language_japanese: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_euc_jp); | ||
break; | ||
case mbfl_no_language_korean: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_euc_kr); | ||
break; | ||
case mbfl_no_language_simplified_chinese: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_euc_cn); | ||
break; | ||
case mbfl_no_language_traditional_chinese: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_euc_tw); | ||
break; | ||
case mbfl_no_language_russian: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_koi8r); | ||
break; | ||
case mbfl_no_language_german: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_8859_15); | ||
break; | ||
case mbfl_no_language_armenian: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_armscii8); | ||
break; | ||
case mbfl_no_language_turkish: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_8859_9); | ||
break; | ||
default: | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_8859_1); | ||
break; | ||
} | ||
} | ||
/* falls back to UTF-8 if an unkown encoding name is given */ | ||
encoding = mbfl_no2encoding(mbfl_no_encoding_utf8); | ||
} | ||
MBSTRG(internal_encoding) = encoding; | ||
MBSTRG(current_internal_encoding) = encoding; | ||
#if HAVE_MBREGEX | ||
{ | ||
const char *enc_name = new_value; | ||
if (FAILURE == php_mb_regex_set_default_mbctype(enc_name TSRMLS_CC)) { | ||
/* falls back to EUC-JP if an unknown encoding name is given */ | ||
enc_name = "EUC-JP"; | ||
/* falls back to UTF-8 if an unknown encoding name is given */ | ||
enc_name = "UTF-8"; | ||
php_mb_regex_set_default_mbctype(enc_name TSRMLS_CC); | ||
} | ||
php_mb_regex_set_mbctype(new_value TSRMLS_CC); | ||
|
@@ -1343,7 +1320,11 @@ static PHP_INI_MH(OnUpdate_mbstring_internal_encoding) | |
} | ||
if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN | ||
|| stage == PHP_INI_STAGE_RUNTIME) { | ||
return _php_mb_ini_mbstring_internal_encoding_set(new_value, new_value_length TSRMLS_CC); | ||
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); | ||
} | ||
} else { | ||
/* the corresponding mbstring globals needs to be set according to the | ||
* ini value in the later stage because it never falls back to the | ||
|
@@ -1450,8 +1431,8 @@ static PHP_INI_MH(OnUpdate_mbstring_http_output_conv_mimetypes) | |
PHP_INI_BEGIN() | ||
PHP_INI_ENTRY("mbstring.language", "neutral", PHP_INI_ALL, OnUpdate_mbstring_language) | ||
PHP_INI_ENTRY("mbstring.detect_order", NULL, PHP_INI_ALL, OnUpdate_mbstring_detect_order) | ||
PHP_INI_ENTRY("mbstring.http_input", "pass", PHP_INI_ALL, OnUpdate_mbstring_http_input) | ||
PHP_INI_ENTRY("mbstring.http_output", "pass", PHP_INI_ALL, OnUpdate_mbstring_http_output) | ||
PHP_INI_ENTRY("mbstring.http_input", NULL, PHP_INI_ALL, OnUpdate_mbstring_http_input) | ||
PHP_INI_ENTRY("mbstring.http_output", NULL, PHP_INI_ALL, OnUpdate_mbstring_http_output) | ||
STD_PHP_INI_ENTRY("mbstring.internal_encoding", NULL, PHP_INI_ALL, OnUpdate_mbstring_internal_encoding, internal_encoding_name, zend_mbstring_globals, mbstring_globals) | ||
PHP_INI_ENTRY("mbstring.substitute_character", NULL, PHP_INI_ALL, OnUpdate_mbstring_substitute_character) | ||
STD_PHP_INI_ENTRY("mbstring.func_overload", "0", | ||
|
@@ -2162,8 +2143,10 @@ PHP_FUNCTION(mb_output_handler) | |
|
||
/* feed the string */ | ||
mbfl_string_init(&string); | ||
string.no_language = MBSTRG(language); | ||
string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding; | ||
/* these are not needed. convd has encoding info. | ||
string.no_language = MBSTRG(language); | ||
string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding; | ||
*/ | ||
string.val = (unsigned char *)arg_string; | ||
string.len = arg_string_len; | ||
mbfl_buffer_converter_feed(MBSTRG(outconv), &string); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raising error might be better, since this code would pass any encoding when invalid encoding name is provided.