Skip to content

Commit 432dc52

Browse files
committed
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.
1 parent 4388eba commit 432dc52

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

ext/filter/filter.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,12 @@ static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval
389389
ce = Z_OBJCE_P(value);
390390
if (!ce->__tostring) {
391391
zval_ptr_dtor(value);
392-
ZVAL_FALSE(value);
392+
/* #67167: doesn't return null on failure for objects */
393+
if (flags & FILTER_NULL_ON_FAILURE) {
394+
ZVAL_NULL(value);
395+
} else {
396+
ZVAL_FALSE(value);
397+
}
393398
return;
394399
}
395400
}

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)