* encoding detector
*/
mbfl_encoding_detector *
-mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz)
+mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz, int strict)
{
mbfl_encoding_detector *identd;
}
identd->filter_list_size = num;
+ /* set strict flag */
+ identd->strict = strict;
+
return identd;
}
while (n >= 0) {
filter = identd->filter_list[n];
if (!filter->flag) {
+ if (identd->strict && filter->status) {
+ continue;
+ }
encoding = filter->encoding->no_encoding;
}
n--;
}
+
+ if (encoding == mbfl_no_encoding_invalid) {
+ n = identd->filter_list_size - 1;
+ while (n >= 0) {
+ filter = identd->filter_list[n];
+ if (!filter->flag) {
+ encoding = filter->encoding->no_encoding;
+ }
+ n--;
+ }
+ }
}
return encoding;
}
enum mbfl_no_encoding
-mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz)
+mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict)
{
const mbfl_encoding *encoding;
- encoding = mbfl_identify_encoding(string, elist, elistsz, 0);
+ encoding = mbfl_identify_encoding(string, elist, elistsz, strict);
if (encoding != NULL &&
encoding->no_encoding > mbfl_no_encoding_charset_min &&
encoding->no_encoding < mbfl_no_encoding_charset_max) {
struct _mbfl_encoding_detector {
mbfl_identify_filter **filter_list;
int filter_list_size;
+ int strict;
};
-MBFLAPI extern mbfl_encoding_detector * mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz);
+MBFLAPI extern mbfl_encoding_detector * mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz, int strict);
MBFLAPI extern void mbfl_encoding_detector_delete(mbfl_encoding_detector *identd);
MBFLAPI extern int mbfl_encoding_detector_feed(mbfl_encoding_detector *identd, mbfl_string *string);
MBFLAPI extern enum mbfl_no_encoding mbfl_encoding_detector_judge(mbfl_encoding_detector *identd);
mbfl_identify_encoding_name(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict);
MBFLAPI extern enum mbfl_no_encoding
-mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz);
+mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict);
/*
* strlen
STD_PHP_INI_BOOLEAN("mbstring.encoding_translation", "0",
PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdate_mbstring_encoding_translation,
encoding_translation, zend_mbstring_globals, mbstring_globals)
+
+ STD_PHP_INI_BOOLEAN("mbstring.strict_detection", "0",
+ PHP_INI_ALL, OnUpdateLong, strict_detection, zend_mbstring_globals, mbstring_globals)
PHP_INI_END()
/* }}} */
MBSTRG(current_filter_illegal_substchar) = 0x3f; /* '?' */
MBSTRG(func_overload) = 0;
MBSTRG(encoding_translation) = 0;
+ MBSTRG(strict_detection) = 0;
pglobals->outconv = NULL;
#if HAVE_MBREGEX
_php_mb_regex_globals_ctor(pglobals TSRMLS_CC);
string.no_encoding = from_encoding;
} else if (size > 1) {
/* auto detect */
- from_encoding = mbfl_identify_encoding_no(&string, list, size);
+ from_encoding = mbfl_identify_encoding_no(&string, list, size, MBSTRG(strict_detection));
if (from_encoding != mbfl_no_encoding_invalid) {
string.no_encoding = from_encoding;
} else {
convert_to_long_ex(arg_strict);
strict = Z_LVAL_PP(arg_strict);
}
+ else {
+ strict = MBSTRG(strict_detection);
+ }
if (size > 0 && list != NULL) {
elist = list;
stack_max = PHP_MBSTR_STACK_BLOCK_SIZE;
stack = (zval ***)safe_emalloc(stack_max, sizeof(zval **), 0);
stack_level = 0;
- identd = mbfl_encoding_detector_new(elist, elistsz);
+ identd = mbfl_encoding_detector_new(elist, elistsz, MBSTRG(strict_detection));
if (identd != NULL) {
n = 2;
while (n < argc || stack_level > 0) {
orig_str.no_encoding = MBSTRG(current_internal_encoding);
if (orig_str.no_encoding == mbfl_no_encoding_invalid
|| orig_str.no_encoding == mbfl_no_encoding_pass) {
- orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size));
+ orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection));
}
pstr = mbfl_mime_header_encode(&orig_str, &conv_str, tran_cs, head_enc, "\n", sizeof("Subject: [PHP-jp nnnnnnnn]"));
if (pstr != NULL) {
if (orig_str.no_encoding == mbfl_no_encoding_invalid
|| orig_str.no_encoding == mbfl_no_encoding_pass) {
- orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size));
+ orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection));
}
pstr = NULL;
mbfl_string_init(&string);
string.no_language = MBSTRG(current_language);
- identd = mbfl_encoding_detector_new(elist, size);
+ identd = mbfl_encoding_detector_new(elist, size, MBSTRG(strict_detection));
if (identd) {
int n = 0;