From: Lars Strojny Date: Sun, 2 Sep 2012 20:10:23 +0000 (+0200) Subject: Bug #49510: Boolean validation fails with FILTER_NULL_ON_FAILURE with empty string... X-Git-Tag: php-5.5.0alpha3~8^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a26390ef0c22be3637795d9b5ab1c445e1d3f847;p=php Bug #49510: Boolean validation fails with FILTER_NULL_ON_FAILURE with empty string or false --- diff --git a/NEWS b/NEWS index 836cf971c0..1dd3e0d991 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,10 @@ PHP NEWS . Allow passing null as a default value to mb_substr() and mb_strcut(). Patch by Alexander Moskaliov via GitHub PR #133. (Lars) +- Filter extension: + . Bug #49510: Boolean validation fails with FILTER_NULL_ON_FAILURE with empty + string or false. (Lars) + ?? ??? 2012, PHP 5.4.7 - Core: diff --git a/ext/filter/filter_private.h b/ext/filter/filter_private.h index daa688b4ac..2ec2f62fae 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 5c3811ab25..4de6b83e00 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 0000000000..3f365cc431 --- /dev/null +++ b/ext/filter/tests/bug49510.phpt @@ -0,0 +1,36 @@ +--TEST-- +#49510 boolean validation fails with FILTER_NULL_ON_FAILURE +--FILE-- + +==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==