Skip to content

Commit 063aba2

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #53037 (FILTER_FLAG_EMPTY_STRING_NULL is not implemented).
1 parent 5a8c917 commit 063aba2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ext/filter/sanitizing_filters.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ void php_filter_string(PHP_INPUT_FILTER_PARAM_DECL)
205205

206206
if (new_len == 0) {
207207
zval_dtor(value);
208-
ZVAL_EMPTY_STRING(value);
208+
if (flags & FILTER_FLAG_EMPTY_STRING_NULL) {
209+
ZVAL_NULL(value);
210+
} else {
211+
ZVAL_EMPTY_STRING(value);
212+
}
209213
return;
210214
}
211215
}
@@ -280,6 +284,9 @@ void php_filter_unsafe_raw(PHP_INPUT_FILTER_PARAM_DECL)
280284
}
281285

282286
php_filter_encode_html(value, enc);
287+
} else if (flags & FILTER_FLAG_EMPTY_STRING_NULL && Z_STRLEN_P(value) == 0) {
288+
zval_dtor(value);
289+
ZVAL_NULL(value);
283290
}
284291
}
285292
/* }}} */

ext/filter/tests/bug53037.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #53037 (FILTER_FLAG_EMPTY_STRING_NULL is not implemented)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("filter")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
var_dump(
8+
filter_var("", FILTER_DEFAULT),
9+
filter_var("", FILTER_DEFAULT, array('flags' => FILTER_FLAG_EMPTY_STRING_NULL))
10+
);
11+
?>
12+
--EXPECT--
13+
string(0) ""
14+
NULL

0 commit comments

Comments
 (0)