]> granicus.if.org Git - php/commitdiff
Partially fix bug #67167 - Wrong return value...
authorLevi Morrison <levim@php.net>
Thu, 3 Sep 2015 00:23:26 +0000 (18:23 -0600)
committerLevi Morrison <levim@php.net>
Thu, 3 Sep 2015 00:23:26 +0000 (18:23 -0600)
...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.

ext/filter/filter.c
ext/filter/tests/bug67167.01.phpt [new file with mode: 0644]
ext/filter/tests/bug67167.02.phpt [new file with mode: 0644]

index 6f8a7a5f8b3f649523f036c212e753228ca46e78..e29a36ab71263633f85329374503d8c8795b48b1 100644 (file)
@@ -389,7 +389,12 @@ static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval
                ce = Z_OBJCE_P(value);
                if (!ce->__tostring) {
                        zval_ptr_dtor(value);
-                       ZVAL_FALSE(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 (file)
index 0000000..09e84fd
--- /dev/null
@@ -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 (file)
index 0000000..3ab0990
--- /dev/null
@@ -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
+