Return empty str from quotemeta() on empty str

This commit is contained in:
Nikita Popov 2019-02-11 09:58:10 +01:00
parent ab48b45f6c
commit fdb85a828a
4 changed files with 7 additions and 5 deletions

View File

@ -148,6 +148,8 @@ PHP 8.0 UPGRADE NOTES
. The 'salt' option of password_hash() is no longer supported. If the 'salt'
option is used a warning is generated, the provided salt is ignored, and a
generated salt is used instead.
. The quotemeta() function will now return an empty string if an empty string
was passed. Previously false was returned.
- Zlib:
. gzgetss() has been removed.

View File

@ -340,7 +340,7 @@ static const func_info_t func_infos[] = {
#endif
FN("substr", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING),
FN("substr_replace", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_STRING),
F1("quotemeta", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING),
F1("quotemeta", MAY_BE_NULL | MAY_BE_STRING),
FN("ucfirst", MAY_BE_NULL | MAY_BE_STRING),
FN("lcfirst", MAY_BE_NULL | MAY_BE_STRING),
F1("ucwords", MAY_BE_NULL | MAY_BE_STRING),

View File

@ -2592,8 +2592,8 @@ PHP_FUNCTION(quotemeta)
old_end = ZSTR_VAL(old) + ZSTR_LEN(old);
if (ZSTR_VAL(old) == old_end) {
RETURN_FALSE;
if (ZSTR_LEN(old) == 0) {
RETURN_EMPTY_STRING();
}
str = zend_string_safe_alloc(2, ZSTR_LEN(old), 0, 0);

View File

@ -1,5 +1,5 @@
--TEST--
Test function quotemeta() - using an empty string is given as str.
Test function quotemeta() - using an empty string is given as str
--CREDITS--
Rodrigo Prado de Jesus <royopa [at] gmail [dot] com>
User Group: PHPSP #PHPTestFestBrasil
@ -9,4 +9,4 @@ $str = "";
var_dump(quotemeta($str));
?>
--EXPECT--
bool(false)
string(0) ""