com php-src: Partially fix bug #67167 - Wrong return value...: NEWS ext/filter/filter.c ext/filter/tests/bug67167.01.phpt
ext/filter/tests/bug67167.02.phpt

From: Date: Fri, 09 Sep 2016 10:45:46 +0000
Subject: com php-src: Partially fix bug #67167 - Wrong return value...: NEWS ext/filter/filter.c ext/filter/tests/bug67167.01.phpt
ext/filter/tests/bug67167.02.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94393@lists.php.net to get a copy of this message
Commit: cb91a51b0052d512c0110ec934a23e263258e461 Author: Levi Morrison <levim@php.net> Wed, 2 Sep 2015 18:23:26 -0600 Committer: Christoph M. Becker <cmbecker69@gmx.de> Fri, 9 Sep 2016 12:45:46 +0200 Parents: 38553e853b65eb84f919e4f5c5b9e702f1842b62 Branches: PHP-5.6 PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cb91a51b0052d512c0110ec934a23e263258e461 Log: 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 432dc527adcbc3bf4809f6315350300d42c16c52) Bugs: https://bugs.php.net/67167 Changed paths: M NEWS M ext/filter/filter.c A ext/filter/tests/bug67167.01.phpt A ext/filter/tests/bug67167.02.phpt Diff: diff --git a/NEWS b/NEWS index 4331aec..420bf36 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ PHP NEWS - Filter: . Fixed bug #72972 (Bad filter for the flags FILTER_FLAG_NO_RES_RANGE and FILTER_FLAG_NO_PRIV_RANGE). (julien) + . Fixed bug #67167 (Wrong return value from FILTER_VALIDATE_BOOLEAN, + FILTER_NULL_ON_FAILURE). (levim, cmb) - GD: . Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette). diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 0a96773..479a63a 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -380,7 +380,13 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options ce = Z_OBJCE_PP(value); if (!ce->__tostring) { - ZVAL_FALSE(*value); + zval_ptr_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; } } diff --git a/ext/filter/tests/bug67167.01.phpt b/ext/filter/tests/bug67167.01.phpt new file mode 100644 index 0000000..09e84fd --- /dev/null +++ b/ext/filter/tests/bug67167.01.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #67167: object with VALIDATE_BOOLEAN and NULL_ON_FAILURE + +--SKIPIF-- +<?php if (!extension_loaded("filter")) die("skip"); ?> + +--FILE-- +<?php +var_dump(filter_var( + new \StdClass(), + FILTER_VALIDATE_BOOLEAN, + FILTER_NULL_ON_FAILURE +)); + +--EXPECTF-- +NULL diff --git a/ext/filter/tests/bug67167.02.phpt b/ext/filter/tests/bug67167.02.phpt new file mode 100644 index 0000000..3ab0990 --- /dev/null +++ b/ext/filter/tests/bug67167.02.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #67167: filter_var(null,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE) returns null + +--SKIPIF-- +<?php if (!extension_loaded("filter")) die("skip"); ?> + +--FILE-- +<?php +var_dump(filter_var( + null, + FILTER_VALIDATE_BOOLEAN, + FILTER_NULL_ON_FAILURE +)); + +--XFAIL-- +Requires php_zval_filter to not use convert_to_string for all filters. + +--EXPECTF-- +NULL +

« previous php.cvs (#94393) next »