Skip to content

Commit cb91a51

Browse files
morrisonlevicmb69
authored andcommitted
Partially fix bug #67167 - Wrong return value...
...from FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE The remainer of the fix would require the filter functions to only convert to string when it makes sense for that particular filter. (cherry picked from commit 432dc52)
1 parent 38553e8 commit cb91a51

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
- Filter:
1010
. Fixed bug #72972 (Bad filter for the flags FILTER_FLAG_NO_RES_RANGE and
1111
FILTER_FLAG_NO_PRIV_RANGE). (julien)
12+
. Fixed bug #67167 (Wrong return value from FILTER_VALIDATE_BOOLEAN,
13+
FILTER_NULL_ON_FAILURE). (levim, cmb)
1214

1315
- GD:
1416
. Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette).

ext/filter/filter.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,13 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
380380

381381
ce = Z_OBJCE_PP(value);
382382
if (!ce->__tostring) {
383-
ZVAL_FALSE(*value);
383+
zval_ptr_dtor(value);
384+
/* #67167: doesn't return null on failure for objects */
385+
if (flags & FILTER_NULL_ON_FAILURE) {
386+
ZVAL_NULL(*value);
387+
} else {
388+
ZVAL_FALSE(*value);
389+
}
384390
return;
385391
}
386392
}

ext/filter/tests/bug67167.01.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #67167: object with VALIDATE_BOOLEAN and NULL_ON_FAILURE
3+
4+
--SKIPIF--
5+
<?php if (!extension_loaded("filter")) die("skip"); ?>
6+
7+
--FILE--
8+
<?php
9+
var_dump(filter_var(
10+
new \StdClass(),
11+
FILTER_VALIDATE_BOOLEAN,
12+
FILTER_NULL_ON_FAILURE
13+
));
14+
15+
--EXPECTF--
16+
NULL

ext/filter/tests/bug67167.02.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #67167: filter_var(null,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE) returns null
3+
4+
--SKIPIF--
5+
<?php if (!extension_loaded("filter")) die("skip"); ?>
6+
7+
--FILE--
8+
<?php
9+
var_dump(filter_var(
10+
null,
11+
FILTER_VALIDATE_BOOLEAN,
12+
FILTER_NULL_ON_FAILURE
13+
));
14+
15+
--XFAIL--
16+
Requires php_zval_filter to not use convert_to_string for all filters.
17+
18+
--EXPECTF--
19+
NULL
20+

0 commit comments

Comments
 (0)