Skip to content

Commit 0c5d337

Browse files
Address review comments
1 parent 148524d commit 0c5d337

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

ext/filter/filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ static void php_filter_call(
585585
}
586586

587587
php_zval_filter(filtered, filter, filter_flags, options, charset);
588-
// Don't wrap in an array if we are throwing an exception
588+
/* Don't wrap in an array if we are throwing an exception */
589589
if (EG(exception)) {
590590
return;
591591
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
FILTER_THROW_ON_FAILURE: successful filters do not throw
3+
--EXTENSIONS--
4+
filter
5+
--GET--
6+
7+
--FILE--
8+
<?php
9+
10+
class MyString {
11+
public function __construct(private string $wrapped) {}
12+
public function __toString(): string { return $this->wrapped; }
13+
}
14+
15+
echo "filter_input:\n";
16+
var_dump(filter_input(INPUT_GET, 'a', FILTER_DEFAULT, FILTER_THROW_ON_FAILURE));
17+
var_dump(filter_input(INPUT_GET, 'a', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR | FILTER_THROW_ON_FAILURE));
18+
var_dump(filter_input(INPUT_GET, 'a', FILTER_VALIDATE_EMAIL, FILTER_THROW_ON_FAILURE));
19+
20+
echo "\nfilter_input_array:\n";
21+
var_dump(filter_input_array(INPUT_GET, ['a' => ['flags' => FILTER_REQUIRE_SCALAR | FILTER_THROW_ON_FAILURE]]));
22+
var_dump(filter_input_array(INPUT_GET, ['a' => ['filter' => FILTER_VALIDATE_EMAIL, 'flags' => FILTER_THROW_ON_FAILURE]]));
23+
24+
echo "\nfilter_var:\n";
25+
var_dump(filter_var('a', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR | FILTER_THROW_ON_FAILURE));
26+
var_dump(filter_var(new MyString('[email protected]'), FILTER_VALIDATE_EMAIL, FILTER_THROW_ON_FAILURE));
27+
var_dump(filter_var('[email protected]', FILTER_VALIDATE_EMAIL, FILTER_THROW_ON_FAILURE));
28+
29+
echo "\nfilter_var_array:\n";
30+
var_dump(filter_var_array(['a' => 'a'], ['a' => ['flags' => FILTER_REQUIRE_SCALAR | FILTER_THROW_ON_FAILURE]]));
31+
var_dump(filter_var_array(['a' => new MyString('bar')], ['a' => ['flags' => FILTER_THROW_ON_FAILURE]]));
32+
var_dump(filter_var_array(['a' => '[email protected]'], ['a' => ['filter' => FILTER_VALIDATE_EMAIL, 'flags' => FILTER_THROW_ON_FAILURE]]));
33+
34+
?>
35+
--EXPECT--
36+
filter_input:
37+
string(27) "[email protected]"
38+
string(27) "[email protected]"
39+
string(27) "[email protected]"
40+
41+
filter_input_array:
42+
array(1) {
43+
["a"]=>
44+
string(27) "[email protected]"
45+
}
46+
array(1) {
47+
["a"]=>
48+
string(27) "[email protected]"
49+
}
50+
51+
filter_var:
52+
string(1) "a"
53+
string(27) "[email protected]"
54+
string(27) "[email protected]"
55+
56+
filter_var_array:
57+
array(1) {
58+
["a"]=>
59+
string(1) "a"
60+
}
61+
array(1) {
62+
["a"]=>
63+
string(3) "bar"
64+
}
65+
array(1) {
66+
["a"]=>
67+
string(27) "[email protected]"
68+
}

ext/filter/tests/throw-on-failure/filter_var_array_failure.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
FILTER_THROW_ON_FAILURE: filter_var_array() failure
33
--EXTENSIONS--
44
filter
5-
--GET--
6-
a=1
75
--FILE--
86
<?php
97

0 commit comments

Comments
 (0)