mirror of
https://github.com/php/php-src.git
synced 2025-08-19 17:04:47 +02:00
Merge pull request #1098
Fix bug #69086 enhancement for mb_convert_encoding
This commit is contained in:
parent
8ad4ef98b6
commit
850a0b5fb6
2 changed files with 64 additions and 25 deletions
|
@ -3148,6 +3148,31 @@ PHP_FUNCTION(mb_strimwidth)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* See mbfl_no_encoding definition for list of unsupported encodings */
|
||||
static inline zend_bool php_mb_is_unsupported_no_encoding(enum mbfl_no_encoding no_enc)
|
||||
{
|
||||
return ((no_enc >= mbfl_no_encoding_invalid && no_enc <= mbfl_no_encoding_qprint)
|
||||
|| (no_enc >= mbfl_no_encoding_utf7 && no_enc <= mbfl_no_encoding_utf7imap)
|
||||
|| (no_enc >= mbfl_no_encoding_jis && no_enc <= mbfl_no_encoding_2022jpms)
|
||||
|| (no_enc >= mbfl_no_encoding_cp50220 && no_enc <= mbfl_no_encoding_cp50222));
|
||||
}
|
||||
|
||||
|
||||
/* See mbfl_no_encoding definition for list of unicode encodings */
|
||||
static inline zend_bool php_mb_is_no_encoding_unicode(enum mbfl_no_encoding no_enc)
|
||||
{
|
||||
return (no_enc >= mbfl_no_encoding_ucs4 && no_enc <= mbfl_no_encoding_utf8_sb);
|
||||
}
|
||||
|
||||
|
||||
/* See mbfl_no_encoding definition for list of UTF-8 encodings */
|
||||
static inline zend_bool php_mb_is_no_encoding_utf8(enum mbfl_no_encoding no_enc)
|
||||
{
|
||||
return (no_enc >= mbfl_no_encoding_utf8 && no_enc <= mbfl_no_encoding_utf8_sb);
|
||||
}
|
||||
|
||||
|
||||
/* {{{ MBSTRING_API char *php_mb_convert_encoding() */
|
||||
MBSTRING_API char * php_mb_convert_encoding(const char *input, size_t length, const char *_to_encoding, const char *_from_encodings, size_t *output_len)
|
||||
{
|
||||
|
@ -3218,7 +3243,28 @@ MBSTRING_API char * php_mb_convert_encoding(const char *input, size_t length, co
|
|||
return NULL;
|
||||
}
|
||||
mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
|
||||
|
||||
if (string.no_encoding == MBSTRG(current_internal_encoding)->no_encoding) {
|
||||
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
|
||||
} else if (php_mb_is_no_encoding_unicode(string.no_encoding) && php_mb_is_no_encoding_unicode(MBSTRG(current_internal_encoding)->no_encoding)) {
|
||||
|
||||
if (php_mb_is_no_encoding_utf8(string.no_encoding)) {
|
||||
|
||||
if (MBSTRG(current_filter_illegal_substchar) > 0xd7ff &&
|
||||
0xe000 > MBSTRG(current_filter_illegal_substchar)
|
||||
) {
|
||||
mbfl_buffer_converter_illegal_substchar(convd, 0x3f);
|
||||
} else {
|
||||
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
|
||||
}
|
||||
|
||||
} else {
|
||||
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
|
||||
}
|
||||
|
||||
} else {
|
||||
mbfl_buffer_converter_illegal_substchar(convd, 0x3f);
|
||||
}
|
||||
|
||||
/* do it */
|
||||
ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
|
||||
|
@ -4764,30 +4810,6 @@ PHP_FUNCTION(mb_check_encoding)
|
|||
/* }}} */
|
||||
|
||||
|
||||
/* See mbfl_no_encoding definition for list of unsupported encodings */
|
||||
static inline zend_bool php_mb_is_unsupported_no_encoding(enum mbfl_no_encoding no_enc)
|
||||
{
|
||||
return ((no_enc >= mbfl_no_encoding_invalid && no_enc <= mbfl_no_encoding_qprint)
|
||||
|| (no_enc >= mbfl_no_encoding_utf7 && no_enc <= mbfl_no_encoding_utf7imap)
|
||||
|| (no_enc >= mbfl_no_encoding_jis && no_enc <= mbfl_no_encoding_2022jpms)
|
||||
|| (no_enc >= mbfl_no_encoding_cp50220 && no_enc <= mbfl_no_encoding_cp50222));
|
||||
}
|
||||
|
||||
|
||||
/* See mbfl_no_encoding definition for list of unicode encodings */
|
||||
static inline zend_bool php_mb_is_no_encoding_unicode(enum mbfl_no_encoding no_enc)
|
||||
{
|
||||
return (no_enc >= mbfl_no_encoding_ucs4 && no_enc <= mbfl_no_encoding_utf8_sb);
|
||||
}
|
||||
|
||||
|
||||
/* See mbfl_no_encoding definition for list of UTF-8 encodings */
|
||||
static inline zend_bool php_mb_is_no_encoding_utf8(enum mbfl_no_encoding no_enc)
|
||||
{
|
||||
return (no_enc >= mbfl_no_encoding_utf8 && no_enc <= mbfl_no_encoding_utf8_sb);
|
||||
}
|
||||
|
||||
|
||||
static inline zend_long php_mb_ord(const char* str, size_t str_len, const char* enc)
|
||||
{
|
||||
enum mbfl_no_encoding no_enc;
|
||||
|
|
17
ext/mbstring/tests/bug69086.phpt
Normal file
17
ext/mbstring/tests/bug69086.phpt
Normal file
|
@ -0,0 +1,17 @@
|
|||
--TEST--
|
||||
Request #69086 (enhancement for mb_convert_encoding)
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
mb_substitute_character(0xfffd);
|
||||
var_dump("?" === mb_convert_encoding("\x80", "Shift_JIS", "EUC-JP"));
|
||||
mb_internal_encoding("UCS-4BE");
|
||||
var_dump("\x00\x00\xff\xfd" === mb_convert_encoding("\x80", "UCS-4BE", "UTF-8"));
|
||||
mb_substitute_character(0xd800);
|
||||
var_dump("\x00\x00\x00\x3f" === mb_convert_encoding("\x80", "UCS-4BE", "UTF-8"));
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
Loading…
Add table
Add a link
Reference in a new issue