summaryrefslogtreecommitdiff
path: root/ext/filter
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-10-25 16:01:25 +0200
committerOndřej Surý <ondrej@sury.org>2012-10-25 16:01:25 +0200
commitb57a2691d5b72c3894e2d4e0f945cecc6b3a1953 (patch)
tree012a1408ce8a738d45ae429ca7d7f5389c159915 /ext/filter
parent45c0aa447e02c80bd21a23245574231a110cf5a1 (diff)
downloadphp-b57a2691d5b72c3894e2d4e0f945cecc6b3a1953.tar.gz
Imported Upstream version 5.4.8upstream/5.4.8
Diffstat (limited to 'ext/filter')
-rw-r--r--ext/filter/filter_private.h6
-rw-r--r--ext/filter/logical_filters.c7
-rw-r--r--ext/filter/tests/bug49510.phpt36
3 files changed, 45 insertions, 4 deletions
diff --git a/ext/filter/filter_private.h b/ext/filter/filter_private.h
index daa688b4a..2ec2f62fa 100644
--- a/ext/filter/filter_private.h
+++ b/ext/filter/filter_private.h
@@ -99,12 +99,14 @@
} \
return; \
-#define PHP_FILTER_TRIM_DEFAULT(p, len) { \
+#define PHP_FILTER_TRIM_DEFAULT(p, len) PHP_FILTER_TRIM_DEFAULT_EX(p, len, 1);
+
+#define PHP_FILTER_TRIM_DEFAULT_EX(p, len, return_if_empty) { \
while ((len > 0) && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\v' || *p == '\n')) { \
p++; \
len--; \
} \
- if (len < 1) { \
+ if (len < 1 && return_if_empty) { \
RETURN_VALIDATION_FAILED \
} \
while (p[len-1] == ' ' || p[len-1] == '\t' || p[len-1] == '\r' || p[len-1] == '\v' || p[len-1] == '\n') { \
diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c
index 5c3811ab2..4de6b83e0 100644
--- a/ext/filter/logical_filters.c
+++ b/ext/filter/logical_filters.c
@@ -235,12 +235,15 @@ void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
int len = Z_STRLEN_P(value);
int ret;
- PHP_FILTER_TRIM_DEFAULT(str, len);
+ PHP_FILTER_TRIM_DEFAULT_EX(str, len, 0);
/* returns true for "1", "true", "on" and "yes"
* returns false for "0", "false", "off", "no", and ""
* null otherwise. */
switch (len) {
+ case 0:
+ ret = 0;
+ break;
case 1:
if (*str == '1') {
ret = 1;
@@ -286,7 +289,7 @@ void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
ret = -1;
}
- if (ret == -1) {
+ if (ret == -1) {
RETURN_VALIDATION_FAILED
} else {
zval_dtor(value);
diff --git a/ext/filter/tests/bug49510.phpt b/ext/filter/tests/bug49510.phpt
new file mode 100644
index 000000000..3f365cc43
--- /dev/null
+++ b/ext/filter/tests/bug49510.phpt
@@ -0,0 +1,36 @@
+--TEST--
+#49510 boolean validation fails with FILTER_NULL_ON_FAILURE
+--FILE--
+<?php
+var_dump(filter_var(false, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var(0, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("0", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("off", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("false", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("no", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+
+var_dump(filter_var(true, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var(1, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("1", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("on", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+var_dump(filter_var("yes", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+
+var_dump(filter_var("invalid", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
+?>
+==DONE==
+--EXPECT--
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+NULL
+==DONE==