mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Fix #73054: default option ignored when object passed to int filter
If an object that can't be converted to string is validated, we must not bail out early, but rather check for a requested default value.
This commit is contained in:
parent
cb91a51b00
commit
23e721fc93
2
NEWS
2
NEWS
@ -11,6 +11,8 @@ PHP NEWS
|
||||
FILTER_FLAG_NO_PRIV_RANGE). (julien)
|
||||
. Fixed bug #67167 (Wrong return value from FILTER_VALIDATE_BOOLEAN,
|
||||
FILTER_NULL_ON_FAILURE). (levim, cmb)
|
||||
. Fixed bug #73054 (default option ignored when object passed to int filter).
|
||||
(cmb)
|
||||
|
||||
- GD:
|
||||
. Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette).
|
||||
|
@ -380,14 +380,14 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
|
||||
|
||||
ce = Z_OBJCE_PP(value);
|
||||
if (!ce->__tostring) {
|
||||
zval_ptr_dtor(value);
|
||||
zval_dtor(*value);
|
||||
/* #67167: doesn't return null on failure for objects */
|
||||
if (flags & FILTER_NULL_ON_FAILURE) {
|
||||
ZVAL_NULL(*value);
|
||||
} else {
|
||||
ZVAL_FALSE(*value);
|
||||
}
|
||||
return;
|
||||
goto handle_default;
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,6 +396,7 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
|
||||
|
||||
filter_func.function(*value, flags, options, charset TSRMLS_CC);
|
||||
|
||||
handle_default:
|
||||
if (
|
||||
options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) &&
|
||||
((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_PP(value) == IS_NULL) ||
|
||||
|
23
ext/filter/tests/bug73054.phpt
Normal file
23
ext/filter/tests/bug73054.phpt
Normal file
@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
Bug #73054 (default option ignored when object passed to int filter)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('filter')) die('skip filter extension not available');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(
|
||||
filter_var(new stdClass, FILTER_VALIDATE_INT, [
|
||||
'options' => ['default' => 2],
|
||||
]),
|
||||
filter_var(new stdClass, FILTER_VALIDATE_INT, [
|
||||
'options' => ['default' => 2],
|
||||
'flags' => FILTER_NULL_ON_FAILURE
|
||||
])
|
||||
);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
int(2)
|
||||
int(2)
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user