]> granicus.if.org Git - php/commitdiff
Allow null as a default value for length in mb_substr() and mb_strcut()
authorLars Strojny <lstrojny@php.net>
Sun, 2 Sep 2012 12:52:05 +0000 (14:52 +0200)
committerLars Strojny <lstrojny@php.net>
Sun, 2 Sep 2012 12:52:05 +0000 (14:52 +0200)
NEWS
ext/mbstring/mbstring.c
ext/mbstring/tests/mb_str_functions_opt-parameter.phpt

diff --git a/NEWS b/NEWS
index 60bb2354500ea492b77b6d739c0b5a396530cf41..836cf971c0d5d6b11af9a525e9e5da5c002d15d7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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:
index 0d2b53a7ca92963ff73820727788dbb7d1c535ca..76654edbf89e7d082afed368124a08bcdaaaddbd 100644 (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
index e4a235df308d71a4953cf85a70014d383403c753..5fb642f9b2ef3209242a46681dd4d5c396f445b4 100644 (file)
@@ -28,5 +28,3 @@ baz
 baz
 foo
 ==DONE==
---XFAIL--
-mb functions fail to allow null instead of actual value