Allow null as a default value for length in mb_substr() and mb_strcut()

This commit is contained in:
Lars Strojny 2012-09-02 14:52:05 +02:00
parent 89948c7fbe
commit 133f610bb1
3 changed files with 16 additions and 6 deletions

4
NEWS
View File

@ -14,6 +14,10 @@ PHP NEWS
. Bug #62987 (Assigning to ArrayObject[null][something] overrides all
undefined variables). (Laruence)
- mbstring:
. Allow passing null as a default value to mb_substr() and mb_strcut(). Patch
by Alexander Moskaliov via GitHub PR #133. (Lars)
?? ??? 2012, PHP 5.4.7
- Core:

View File

@ -2715,9 +2715,10 @@ PHP_FUNCTION(mb_substr)
char *str, *encoding;
long from, len;
int mblen, str_len, encoding_len;
zval **z_len = NULL;
mbfl_string string, result, *ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", &str, &str_len, &from, &len, &encoding, &encoding_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|Zs", &str, &str_len, &from, &z_len, &encoding, &encoding_len) == FAILURE) {
return;
}
@ -2736,8 +2737,11 @@ PHP_FUNCTION(mb_substr)
string.val = (unsigned char *)str;
string.len = str_len;
if (argc < 3) {
if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) {
len = str_len;
} else {
convert_to_long_ex(z_len);
len = Z_LVAL_PP(z_len);
}
/* measures length */
@ -2788,13 +2792,14 @@ PHP_FUNCTION(mb_strcut)
char *encoding;
long from, len;
int encoding_len;
zval **z_len = NULL;
mbfl_string string, result, *ret;
mbfl_string_init(&string);
string.no_language = MBSTRG(language);
string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", (char **)&string.val, (int **)&string.len, &from, &len, &encoding, &encoding_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|Zs", (char **)&string.val, (int **)&string.len, &from, &z_len, &encoding, &encoding_len) == FAILURE) {
return;
}
@ -2806,8 +2811,11 @@ PHP_FUNCTION(mb_strcut)
}
}
if (argc < 3) {
if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) {
len = string.len;
} else {
convert_to_long_ex(z_len);
len = Z_LVAL_PP(z_len);
}
/* if "from" position is negative, count start position from the end

View File

@ -28,5 +28,3 @@ baz
baz
foo
==DONE==
--XFAIL--
mb functions fail to allow null instead of actual value