]> granicus.if.org Git - php/commitdiff
Fixed bug #53037 (FILTER_FLAG_EMPTY_STRING_NULL is not implemented).
authorIlia Alshanetsky <iliaa@php.net>
Sun, 3 Apr 2011 16:30:31 +0000 (16:30 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 3 Apr 2011 16:30:31 +0000 (16:30 +0000)
NEWS
ext/filter/sanitizing_filters.c
ext/filter/tests/bug53037.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1ca5022ce723dd604b87c024188774697b3a0310..534e075ae9e6195d3a4d4b0a16a2507d7656589a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,9 @@ PHP                                                                        NEWS
 - DBA extension:
   . Fixed bug #54242 (dba_insert returns true if key already exists). (Felipe)
 
+- Filter extension:
+  . Fixed bug #53037 (FILTER_FLAG_EMPTY_STRING_NULL is not implemented). (Ilia)
+  
 - LDAP extension:
   . Fixed bug #53339 (Fails to build when compilng with gcc 4.5 and DSO
     libraries). (Clint Byrum, Raphael)
index 56a5d72639bd8572c7f763a5a2a2f728edd3d209..c79c09b9176b85466f90aa84af663cc25db7dc2b 100644 (file)
@@ -205,7 +205,11 @@ void php_filter_string(PHP_INPUT_FILTER_PARAM_DECL)
 
        if (new_len == 0) {
                zval_dtor(value);
-               ZVAL_EMPTY_STRING(value);
+               if (flags & FILTER_FLAG_EMPTY_STRING_NULL) {
+                       ZVAL_NULL(value);
+               } else {
+                       ZVAL_EMPTY_STRING(value);                       
+               }
                return;
        }
 }
@@ -280,6 +284,9 @@ void php_filter_unsafe_raw(PHP_INPUT_FILTER_PARAM_DECL)
                }
 
                php_filter_encode_html(value, enc);     
+       } else if (flags & FILTER_FLAG_EMPTY_STRING_NULL && Z_STRLEN_P(value) == 0) {
+               zval_dtor(value);
+               ZVAL_NULL(value);
        }
 }
 /* }}} */
diff --git a/ext/filter/tests/bug53037.phpt b/ext/filter/tests/bug53037.phpt
new file mode 100644 (file)
index 0000000..4a1e9e3
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #53037 (FILTER_FLAG_EMPTY_STRING_NULL is not implemented)
+--SKIPIF--
+<?php if (!extension_loaded("filter")) die("skip"); ?>
+--FILE--
+<?php
+var_dump(
+       filter_var("", FILTER_DEFAULT),
+    filter_var("", FILTER_DEFAULT, array('flags' => FILTER_FLAG_EMPTY_STRING_NULL))
+);
+?>
+--EXPECT--     
+string(0) ""
+NULL