Merge branch 'master' into immutable

* master:
  Remove the "auto" encoding
  Fixed bug #77025
  Add vtbls for EUC-TW encoding
This commit is contained in:
Dmitry Stogov 2018-10-17 14:43:38 +03:00
commit cd0c36c3f9
6 changed files with 60 additions and 20 deletions

View File

@ -66,7 +66,9 @@ const mbfl_encoding mbfl_encoding_euc_tw = {
"EUC-TW",
(const char *(*)[])&mbfl_encoding_euc_tw_aliases,
mblen_table_euctw,
MBFL_ENCTYPE_MBCS
MBFL_ENCTYPE_MBCS,
&vtbl_euctw_wchar,
&vtbl_wchar_euctw
};
const struct mbfl_identify_vtbl vtbl_identify_euctw = {

View File

@ -36,6 +36,11 @@
#include "mbfilter.h"
const struct mbfl_convert_vtbl vtbl_8bit_wchar;
const struct mbfl_convert_vtbl vtbl_wchar_8bit;
static int mbfl_filt_conv_8bit_wchar(int c, mbfl_convert_filter *filter);
static int mbfl_filt_conv_wchar_8bit(int c, mbfl_convert_filter *filter);
static const char *mbfl_encoding_8bit_aliases[] = {"binary", NULL};
const mbfl_encoding mbfl_encoding_8bit = {
@ -45,6 +50,42 @@ const mbfl_encoding mbfl_encoding_8bit = {
(const char *(*)[])&mbfl_encoding_8bit_aliases,
NULL,
MBFL_ENCTYPE_SBCS,
NULL,
NULL
&vtbl_8bit_wchar,
&vtbl_wchar_8bit
};
const struct mbfl_convert_vtbl vtbl_8bit_wchar = {
mbfl_no_encoding_8bit,
mbfl_no_encoding_wchar,
mbfl_filt_conv_common_ctor,
mbfl_filt_conv_common_dtor,
mbfl_filt_conv_8bit_wchar,
mbfl_filt_conv_common_flush
};
const struct mbfl_convert_vtbl vtbl_wchar_8bit = {
mbfl_no_encoding_wchar,
mbfl_no_encoding_8bit,
mbfl_filt_conv_common_ctor,
mbfl_filt_conv_common_dtor,
mbfl_filt_conv_wchar_8bit,
mbfl_filt_conv_common_flush
};
#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
static int mbfl_filt_conv_8bit_wchar(int c, mbfl_convert_filter *filter)
{
return (*filter->output_function)(c, filter->data);
}
static int mbfl_filt_conv_wchar_8bit(int c, mbfl_convert_filter *filter)
{
if (c >= 0 && c < 0x100) {
CK((*filter->output_function)(c, filter->data));
} else {
CK(mbfl_filt_conv_illegal_output(c, filter));
}
return c;
}

View File

@ -114,22 +114,8 @@
#endif
static const char *mbfl_encoding_auto_aliases[] = {"unknown", NULL};
static const mbfl_encoding mbfl_encoding_auto = {
mbfl_no_encoding_auto,
"auto",
NULL,
(const char *(*)[])&mbfl_encoding_auto_aliases,
NULL,
0,
NULL,
NULL
};
static const mbfl_encoding *mbfl_encoding_ptr_list[] = {
&mbfl_encoding_pass,
&mbfl_encoding_auto,
&mbfl_encoding_wchar,
&mbfl_encoding_byte2be,
&mbfl_encoding_byte2le,

View File

@ -36,7 +36,6 @@
enum mbfl_no_encoding {
mbfl_no_encoding_invalid = -1,
mbfl_no_encoding_pass,
mbfl_no_encoding_auto,
mbfl_no_encoding_wchar,
mbfl_no_encoding_byte2be,
mbfl_no_encoding_byte2le,

View File

@ -0,0 +1,12 @@
--TEST--
Bug #77025: mb_strpos throws Unknown encoding or conversion error
--FILE--
<?php
var_dump(mb_strpos('Hello', 'e', 0, '8bit'));
var_dump(mb_stripos('Hello', 'e', 0, '8bit'));
?>
--EXPECT--
int(1)
int(1)

View File

@ -38,7 +38,7 @@ echo "== INVALID PARAMETER ==\n";
var_dump(mb_preferred_mime_name('BAD_NAME'));
// No preferred name
var_dump(mb_preferred_mime_name('auto'));
var_dump(mb_preferred_mime_name('pass'));
?>
--EXPECTF--
Shift_JIS
@ -55,5 +55,5 @@ UCS-4
Warning: mb_preferred_mime_name(): Unknown encoding "BAD_NAME" in %s on line %d
bool(false)
Warning: mb_preferred_mime_name(): No MIME preferred name corresponding to "auto" in %s on line %d
Warning: mb_preferred_mime_name(): No MIME preferred name corresponding to "pass" in %s on line %d
bool(false)