diff options
author | Colin O'Dell <colinodell@gmail.com> | 2019-10-21 14:49:08 -0400 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-10-22 12:09:04 +0200 |
commit | e6d3146bdc943ead15209c4070a51a35abc99167 (patch) | |
tree | b385002170f2fd012ebe3c84b2bf0e2a452d3358 /ext/iconv | |
parent | 8ccd58baca77b6fc4c818ac8b4f8af10370af5ad (diff) | |
download | php-git-e6d3146bdc943ead15209c4070a51a35abc99167.tar.gz |
Accept null lengths for substr functions()
If a null $length is passed to any of these functions, behave as if no
parameter was passed:
- substr()
- substr_count()
- substr_compare()
- iconv_substr()
Diffstat (limited to 'ext/iconv')
-rw-r--r-- | ext/iconv/iconv.c | 7 | ||||
-rw-r--r-- | ext/iconv/iconv.stub.php | 2 | ||||
-rw-r--r-- | ext/iconv/iconv_arginfo.h | 2 | ||||
-rw-r--r-- | ext/iconv/tests/iconv_substr.phpt | 3 |
4 files changed, 9 insertions, 5 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 9fab00a746..9e4c52d252 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -2028,13 +2028,14 @@ PHP_FUNCTION(iconv_substr) size_t charset_len = 0; zend_string *str; zend_long offset, length = 0; + zend_bool len_is_null = 1; php_iconv_err_t err; smart_str retval = {0}; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|ls", - &str, &offset, &length, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l!s", + &str, &offset, &length, &len_is_null, &charset, &charset_len) == FAILURE) { return; } @@ -2044,7 +2045,7 @@ PHP_FUNCTION(iconv_substr) RETURN_FALSE; } - if (ZEND_NUM_ARGS() < 3) { + if (len_is_null) { length = ZSTR_LEN(str); } diff --git a/ext/iconv/iconv.stub.php b/ext/iconv/iconv.stub.php index dfa2593f0c..965c4a7e96 100644 --- a/ext/iconv/iconv.stub.php +++ b/ext/iconv/iconv.stub.php @@ -4,7 +4,7 @@ function iconv_strlen(string $str, string $charset = UNKNOWN) {} /** @return string|false */ -function iconv_substr(string $str, int $offset, int $length = UNKNOWN, string $charset = UNKNOWN) {} +function iconv_substr(string $str, int $offset, ?int $length = null, string $charset = UNKNOWN) {} /** @return int|false */ function iconv_strpos(string $haystack, string $needle, int $offset = 0, string $charset = UNKNOWN) {} diff --git a/ext/iconv/iconv_arginfo.h b/ext/iconv/iconv_arginfo.h index 1587b0fadb..462b1cfbe4 100644 --- a/ext/iconv/iconv_arginfo.h +++ b/ext/iconv/iconv_arginfo.h @@ -8,7 +8,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_iconv_substr, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1) ZEND_ARG_TYPE_INFO(0, charset, IS_STRING, 0) ZEND_END_ARG_INFO() diff --git a/ext/iconv/tests/iconv_substr.phpt b/ext/iconv/tests/iconv_substr.phpt index 6ca545b2ea..2a514e6f61 100644 --- a/ext/iconv/tests/iconv_substr.phpt +++ b/ext/iconv/tests/iconv_substr.phpt @@ -34,6 +34,7 @@ foo("あいうえおかきくけこさしす", 5, 7, "EUC-JP"); bar("This is a test", 100000); bar("This is a test", 0, 100000); bar("This is a test", -3); +bar("This is a test", -3, null); bar("This is a test", 0, -9); bar("This is a test", 0, -100000); bar("This is a test", -9, -100000); @@ -50,6 +51,8 @@ string(14) "This is a test" string(14) "This is a test" string(3) "est" string(3) "est" +string(3) "est" +string(3) "est" string(5) "This " string(5) "This " bool(false) |