From 7ff8b9b0907c83b488081599cc43d0323737fbfb Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Wed, 20 Sep 2006 20:30:19 +0000 Subject: [PATCH] Bug fixes for substr_replace(). --- Zend/zend_API.c | 2 +- ext/standard/array.c | 4 ---- ext/standard/string.c | 28 ++++------------------------ unicode-progress.txt | 8 +------- 4 files changed, 6 insertions(+), 36 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 923cad4960..7c65a8e4d3 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3460,7 +3460,7 @@ ZEND_API zval *zend_read_static_property(zend_class_entry *scope, char *name, in ZEND_API zend_uchar zend_get_unified_string_type(int num_args TSRMLS_DC, ...) { va_list ap; - int best_type = UG(unicode) ? IS_UNICODE : IS_STRING; + int best_type = ZEND_STR_TYPE; int type; if (num_args <= 0) return (zend_uchar)-1; diff --git a/ext/standard/array.c b/ext/standard/array.c index 54623a9e95..ac284f45f1 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1690,10 +1690,6 @@ PHP_FUNCTION(range) /* Unify types */ str_type = zend_get_unified_string_type(2 TSRMLS_CC, Z_TYPE_P(zlow), Z_TYPE_P(zhigh)); - if (str_type == (zend_uchar)-1) { - zend_error(E_WARNING, "Cannot mix binary and Unicode parameters"); - return; - } convert_to_explicit_type(zlow, str_type); convert_to_explicit_type(zhigh, str_type); diff --git a/ext/standard/string.c b/ext/standard/string.c index c738b87fbd..12e38db776 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2319,10 +2319,6 @@ PHP_FUNCTION(stristr) } if (Z_TYPE_PP(haystack) != Z_TYPE_PP(needle)) { str_type = zend_get_unified_string_type(2 TSRMLS_CC, Z_TYPE_PP(haystack), Z_TYPE_PP(needle)); - if (str_type == (zend_uchar)-1) { - zend_error(E_WARNING, "Cannot mix binary and Unicode parameters"); - return; - } convert_to_explicit_type_ex(haystack, str_type); convert_to_explicit_type_ex(needle, str_type); } @@ -2628,10 +2624,6 @@ PHP_FUNCTION(stripos) } if (Z_TYPE_PP(haystack) != Z_TYPE_PP(needle)) { str_type = zend_get_unified_string_type(2 TSRMLS_CC, Z_TYPE_PP(haystack), Z_TYPE_PP(needle)); - if (str_type == (zend_uchar)-1) { - zend_error(E_WARNING, "Cannot mix binary and Unicode parameters"); - return; - } convert_to_explicit_type_ex(haystack, str_type); convert_to_explicit_type_ex(needle, str_type); } @@ -2739,10 +2731,6 @@ PHP_FUNCTION(strrpos) if (Z_TYPE_PP(zneedle) == IS_UNICODE || Z_TYPE_PP(zneedle) == IS_STRING) { if (Z_TYPE_PP(zneedle) != Z_TYPE_PP(zhaystack)) { str_type = zend_get_unified_string_type(2 TSRMLS_CC, Z_TYPE_PP(zhaystack), Z_TYPE_PP(zneedle)); - if (str_type == (zend_uchar)-1) { - zend_error(E_WARNING, "Cannot mix binary and Unicode parameters"); - return; - } convert_to_explicit_type_ex(zhaystack, str_type); convert_to_explicit_type_ex(zneedle, str_type); } @@ -3264,8 +3252,8 @@ PHP_FUNCTION(substr_replace) zval **tmp_str = NULL, **tmp_from = NULL, **tmp_repl = NULL, **tmp_len= NULL; zend_uchar str_type; - if (argc < 3 || argc > 4 || zend_get_parameters_ex(argc, &str, &repl, &from, &len) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZZ|Z", &str, &repl, &from, &len) == FAILURE) { + return; } if (Z_TYPE_PP(str) != IS_ARRAY && Z_TYPE_PP(str) != IS_UNICODE && @@ -3323,10 +3311,6 @@ PHP_FUNCTION(substr_replace) if (tmp_repl && Z_TYPE_PP(str) != Z_TYPE_PP(tmp_repl)) { str_type = zend_get_unified_string_type(2 TSRMLS_CC, Z_TYPE_PP(str), Z_TYPE_PP(tmp_repl)); - if (str_type == (zend_uchar)-1) { - zend_error(E_WARNING, "Cannot mix binary and Unicode types"); - return; - } convert_to_explicit_type_ex(str, str_type); convert_to_explicit_type_ex(tmp_repl, str_type); } @@ -3357,7 +3341,7 @@ PHP_FUNCTION(substr_replace) zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(str), &pos_str); while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(str), (void **) &tmp_str, &pos_str) == SUCCESS) { - if (Z_TYPE_PP(tmp_str) != IS_UNICODE && Z_TYPE_PP(tmp_str) != IS_STRING && Z_TYPE_PP(tmp_str) != IS_STRING) { + if (Z_TYPE_PP(tmp_str) != IS_UNICODE && Z_TYPE_PP(tmp_str) != IS_STRING) { convert_to_text_ex(tmp_str); } @@ -3388,7 +3372,7 @@ PHP_FUNCTION(substr_replace) if (Z_TYPE_PP(repl) == IS_ARRAY) { if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(repl), (void **) &tmp_repl, &pos_repl)) { - if (Z_TYPE_PP(repl) != IS_UNICODE && Z_TYPE_PP(repl) != IS_STRING && Z_TYPE_PP(repl) != IS_STRING) { + if (Z_TYPE_PP(tmp_repl) != IS_UNICODE && Z_TYPE_PP(tmp_repl) != IS_STRING) { convert_to_text_ex(tmp_repl); } zend_hash_move_forward_ex(Z_ARRVAL_PP(repl), &pos_repl); @@ -3401,10 +3385,6 @@ PHP_FUNCTION(substr_replace) if (tmp_repl && Z_TYPE_PP(tmp_str) != Z_TYPE_PP(tmp_repl)) { str_type = zend_get_unified_string_type(2 TSRMLS_CC, Z_TYPE_PP(tmp_str), Z_TYPE_PP(tmp_repl)); - if (str_type == (zend_uchar)-1) { - zend_error(E_WARNING, "Cannot mix binary and Unicode types"); - return; - } convert_to_explicit_type_ex(tmp_str, str_type); convert_to_explicit_type_ex(tmp_repl, str_type); } diff --git a/unicode-progress.txt b/unicode-progress.txt index 392d0415c7..e79126d09a 100644 --- a/unicode-progress.txt +++ b/unicode-progress.txt @@ -72,16 +72,9 @@ ext/standard strnatcmp(), strnatcasecmp() Params API. The rest depends on porting of strnatcmp.c - strrchr() - Needs update so that it doesn't try to find half of a surrogate - pair. - strtr() Check on Derick's progress. - substr_replace() - Params API, test - wordwrap() Upgrade, do wordwrapping on codepoint (or glyph ?) level, maybe use additional whitespace chars instead of just space. @@ -129,6 +122,7 @@ ext/standard max() range() shuffle() + strrchr() end(), prev(), next(), reset(), current(), key() -- 2.50.1