php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch bug51344-fix-wrong-return-value-for-null-flag for Filter related Bug #51344

Patch version 2010-04-10 23:13 UTC

Return to Bug #51344 | Download this patch
Patch Revisions:

Developer: mats.lindh@gmail.com

Index: ext/filter/tests/bug51344.phpt
===================================================================
--- ext/filter/tests/bug51344.phpt	(revision 0)
+++ ext/filter/tests/bug51344.phpt	(revision 0)
@@ -0,0 +1,34 @@
+--TEST--
+Bug #51344 (FILTER_NULL_ON_FAILURE not handled properly in filter_input)
+--INI--
+filter.default=unsafe_raw
+filter.default_flags=
+--GET--
+arg1=yes&arg3=no
+--FILE--
+<?php
+$var1 = filter_var($_GET["arg1"], FILTER_VALIDATE_BOOLEAN);
+$var2 = filter_var(null, FILTER_VALIDATE_BOOLEAN);
+$var3 = filter_var($_GET["arg3"], FILTER_VALIDATE_BOOLEAN);
+
+// filtering by input
+$input1 = filter_input(INPUT_GET, "arg1", FILTER_VALIDATE_BOOLEAN);
+$input2 = filter_input(INPUT_GET, "arg2", FILTER_VALIDATE_BOOLEAN);
+$input3 = filter_input(INPUT_GET, "arg3", FILTER_VALIDATE_BOOLEAN);
+
+// as expected...
+var_dump($var1);
+var_dump($var2);
+var_dump($var3);
+
+// NULL is not an expected return unless the FILTER_NULL_ON_FAILURE flag is set...
+var_dump($input1);
+var_dump($input2);
+var_dump($input3);
+--EXPECT--
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
\ No newline at end of file
Index: ext/filter/filter.c
===================================================================
--- ext/filter/filter.c	(revision 297818)
+++ ext/filter/filter.c	(working copy)
@@ -781,9 +781,9 @@
 			}
 		}
 		if (filter_flags & FILTER_NULL_ON_FAILURE) {
+			RETURN_NULL();
+		} else {
 			RETURN_FALSE;
-		} else {
-			RETURN_NULL();
 		}
 	}
 
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 12:03:44 2022 UTC