Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'PHP-5.4'

  • Loading branch information...
commit 6fc2962b9aa1aa8fe41400f2a895a09a16034e8c 2 parents cdb9fe9 + a26390e
Lars Strojny lstrojny authored
6 ext/filter/filter_private.h
@@ -99,12 +99,14 @@
99 99 } \
100 100 return; \
101 101
102   -#define PHP_FILTER_TRIM_DEFAULT(p, len) { \
  102 +#define PHP_FILTER_TRIM_DEFAULT(p, len) PHP_FILTER_TRIM_DEFAULT_EX(p, len, 1);
  103 +
  104 +#define PHP_FILTER_TRIM_DEFAULT_EX(p, len, return_if_empty) { \
103 105 while ((len > 0) && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\v' || *p == '\n')) { \
104 106 p++; \
105 107 len--; \
106 108 } \
107   - if (len < 1) { \
  109 + if (len < 1 && return_if_empty) { \
108 110 RETURN_VALIDATION_FAILED \
109 111 } \
110 112 while (p[len-1] == ' ' || p[len-1] == '\t' || p[len-1] == '\r' || p[len-1] == '\v' || p[len-1] == '\n') { \
7 ext/filter/logical_filters.c
@@ -235,12 +235,15 @@ void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
235 235 int len = Z_STRLEN_P(value);
236 236 int ret;
237 237
238   - PHP_FILTER_TRIM_DEFAULT(str, len);
  238 + PHP_FILTER_TRIM_DEFAULT_EX(str, len, 0);
239 239
240 240 /* returns true for "1", "true", "on" and "yes"
241 241 * returns false for "0", "false", "off", "no", and ""
242 242 * null otherwise. */
243 243 switch (len) {
  244 + case 0:
  245 + ret = 0;
  246 + break;
244 247 case 1:
245 248 if (*str == '1') {
246 249 ret = 1;
@@ -286,7 +289,7 @@ void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
286 289 ret = -1;
287 290 }
288 291
289   - if (ret == -1) {
  292 + if (ret == -1) {
290 293 RETURN_VALIDATION_FAILED
291 294 } else {
292 295 zval_dtor(value);
36 ext/filter/tests/bug49510.phpt
... ... @@ -0,0 +1,36 @@
  1 +--TEST--
  2 +#49510 boolean validation fails with FILTER_NULL_ON_FAILURE
  3 +--FILE--
  4 +<?php
  5 +var_dump(filter_var(false, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  6 +var_dump(filter_var(0, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  7 +var_dump(filter_var("0", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  8 +var_dump(filter_var("off", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  9 +var_dump(filter_var("", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  10 +var_dump(filter_var("false", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  11 +var_dump(filter_var("no", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  12 +
  13 +var_dump(filter_var(true, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  14 +var_dump(filter_var(1, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  15 +var_dump(filter_var("1", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  16 +var_dump(filter_var("on", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  17 +var_dump(filter_var("yes", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  18 +
  19 +var_dump(filter_var("invalid", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  20 +?>
  21 +==DONE==
  22 +--EXPECT--
  23 +bool(false)
  24 +bool(false)
  25 +bool(false)
  26 +bool(false)
  27 +bool(false)
  28 +bool(false)
  29 +bool(false)
  30 +bool(true)
  31 +bool(true)
  32 +bool(true)
  33 +bool(true)
  34 +bool(true)
  35 +NULL
  36 +==DONE==

0 comments on commit 6fc2962

Please sign in to comment.
Something went wrong with that request. Please try again.