diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-10-07 13:04:06 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-10-30 10:53:45 +0100 |
commit | 93ba3abe63cd339c52cf5774e948bb35d8e73049 (patch) | |
tree | 4a7d1e418c79fb9cd8276a6816a07a4c5a7594e5 /ext/standard/string.c | |
parent | becda2e0418d4efb55fca40b1170ca67cfbdb4e0 (diff) | |
download | php-git-93ba3abe63cd339c52cf5774e948bb35d8e73049.tar.gz |
Warn on strtr(["" => "x"])
Previously:
* If only ["" => "x"] was present, the original string was returned
without warning.
* If both ["" => "x"] and at least one more element was present,
false was returned without warning.
New behavior:
* Ignore "" keys in the replacement array (and perform any remaining
replacement).
* Throw a warning indicating that an empty string replacement has
been ignored.
Closes GH-4792.
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r-- | ext/standard/string.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c index 639e443c06..a23c85c6d3 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2819,8 +2819,8 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p } else { len = ZSTR_LEN(str_key); if (UNEXPECTED(len < 1)) { - efree(num_bitset); - RETURN_FALSE; + php_error_docref(NULL, E_WARNING, "Ignoring replacement of empty string"); + continue; } else if (UNEXPECTED(len > slen)) { /* skip long patterns */ continue; @@ -3294,6 +3294,7 @@ PHP_FUNCTION(strtr) } replace = zval_get_tmp_string(entry, &tmp_replace); if (ZSTR_LEN(str_key) < 1) { + php_error_docref(NULL, E_WARNING, "Ignoring replacement of empty string"); RETVAL_STR_COPY(str); } else if (ZSTR_LEN(str_key) == 1) { RETVAL_STR(php_char_to_str_ex(str, |