Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions ext/standard/tests/filters/filter_errors.inc
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<?php

function filter_errors_skipif($needle) {
if (!function_exists('fnmatch')) {
die('skip fnmatch() not available');
}
$filters = stream_get_filters();
foreach($filters as $filter) {
if (fnmatch($filter, $needle)) return;
}
die("skip $needle not available");
}

function filter_errors_test($filter, $data) {

echo "test filtering of buffered data\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
Filter errors: convert.base64-decode
--SKIPIF--
<?php require 'filter_errors.inc'; filter_errors_skipif('convert.base64-decode'); ?>
--FILE--
<?php
require 'filter_errors.inc';
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/filters/filter_errors_zlib_inflate.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--TEST--
Filter errors: zlib.inflate
--SKIPIF--
<?php require 'filter_errors.inc'; filter_errors_skipif('zlib.inflate'); ?>
--EXTENSIONS--
zlib
--FILE--
<?php
require 'filter_errors.inc';
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/filters/gh13264.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--TEST--
GH-13264: fgets() and stream_get_line() do not return false on filter fatal error
--SKIPIF--
<?php require 'filter_errors.inc'; filter_errors_skipif('zlib.inflate'); ?>
--EXTENSIONS--
zlib
--FILE--
<?php
function create_stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
stream_filter_register() with a class that coerces the $consumed parameter of filter method
--XFAIL--
This leaks memory
--FILE--
<?php

class foo extends php_user_filter {
public function filter($in, $out, &$consumed, bool $closing): int {
$consumed = new stdClass();
return PSFS_PASS_ON;
}
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)
resource(4) of type (stream filter)

Warning: Object of class stdClass could not be converted to int in %s on line %d

Warning: fwrite(): Unprocessed filter buckets remaining on input brigade in %s on line %d
int(1)

Warning: Object of class stdClass could not be converted to int in Unknown on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
stream_filter_register() with a class name that exist but does not extend php_user_filter nor mock anything
--FILE--
<?php
class foo {

}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)

Deprecated: Creation of dynamic property foo::$filtername is deprecated in %s on line %d

Deprecated: Creation of dynamic property foo::$params is deprecated in %s on line %d
resource(%d) of type (stream filter)

Warning: fwrite(): Unprocessed filter buckets remaining on input brigade in %s on line %d

Fatal error: Uncaught Error: Invalid callback foo::filter, class foo does not have a method "filter" in %s:%d
Stack trace:
#0 %s(%d): fwrite(Resource id #%d, 'Hello\n')
#1 {main}
thrown in %s on line %d

Fatal error: Invalid callback foo::filter, class foo does not have a method "filter" in Unknown on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
stream_filter_register() with a class name exist but does not extend php_user_filter and defines a $filtername prop with different type
--FILE--
<?php
class foo {
public array $filtername;
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)

Deprecated: Creation of dynamic property foo::$params is deprecated in %s on line %d

Fatal error: Uncaught TypeError: Cannot assign string to property foo::$filtername of type array in %s:%d
Stack trace:
#0 %s(%d): stream_filter_append(Resource id #2, 'invalid_filter')
#1 {main}
thrown in %s on line %d

Fatal error: Invalid callback foo::filter, class foo does not have a method "filter" in Unknown on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
stream_filter_register() with a class name exist but does not extend php_user_filter and cannot have dynamic properties
--FILE--
<?php

var_dump(stream_filter_register("invalid_filter", "SensitiveParameter"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)

Fatal error: Uncaught Error: Cannot create dynamic property SensitiveParameter::$filtername in %s:%d
Stack trace:
#0 %s(%d): stream_filter_append(Resource id #%d, 'invalid_filter')
#1 {main}

Next Error: Cannot create dynamic property SensitiveParameter::$params in %s:%d
Stack trace:
#0 %s(%d): stream_filter_append(Resource id #%d, 'invalid_filter')
#1 {main}
thrown in %s on line %d

Fatal error: Invalid callback SensitiveParameter::filter, class SensitiveParameter does not have a method "filter" in Unknown on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
stream_filter_register() with a class name exist but does not extend php_user_filter and defines a private $filtername prop
--FILE--
<?php
class foo {
private $filtername;
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)

Deprecated: Creation of dynamic property foo::$params is deprecated in %s on line %d

Fatal error: Uncaught Error: Cannot access private property foo::$filtername in %s:%d
Stack trace:
#0 %s(%d): stream_filter_append(Resource id #2, 'invalid_filter')
#1 {main}
thrown in %s on line %d

Fatal error: Invalid callback foo::filter, class foo does not have a method "filter" in Unknown on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
stream_filter_register() with a class that has a onclose method that throws
--FILE--
<?php
class foo extends php_user_filter {
public function onclose(): void {
throw new Exception("No");
}
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)
resource(4) of type (stream filter)

Warning: fwrite(): Unprocessed filter buckets remaining on input brigade in %s on line %d
bool(false)

Fatal error: Uncaught Exception: No in %s:%d
Stack trace:
#0 [internal function]: foo->onclose()
#1 {main}
thrown in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
stream_filter_register() with a class that has a oncreate method that throws
--FILE--
<?php
class foo extends php_user_filter {
public function oncreate(): bool {
throw new Exception("No");
}
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)

Fatal error: Uncaught Exception: No in %s:%d
Stack trace:
#0 [internal function]: foo->oncreate()
#1 %s(%d): stream_filter_append(Resource id #2, 'invalid_filter')
#2 {main}
thrown in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
stream_filter_register() with a filter method always returning PSFS_FEED_ME
--FILE--
<?php
class foo extends php_user_filter {
public function filter($in, $out, &$consumed, bool $closing): int {
return PSFS_FEED_ME;
}
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)
resource(4) of type (stream filter)

Warning: fwrite(): Unprocessed filter buckets remaining on input brigade in %s on line %d
int(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
stream_filter_register() with a class name exist that mocks php_user_filter with a filter method
--XFAIL--
This leaks memory
--FILE--
<?php

class foo {
public $filtername;
public $params;

public function filter($in, $out, &$consumed, bool $closing): int {
return PSFS_PASS_ON;
}
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)
resource(4) of type (stream filter)

Warning: fwrite(): Unprocessed filter buckets remaining on input brigade in %s on line %d
int(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
stream_filter_register() with a class name exist that mocks php_user_filter with a filter method returning not an int
--FILE--
<?php

class foo {
public $filtername;
public $params;

public function filter($in, $out, &$consumed, bool $closing) {
return new stdClass();
}
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)
resource(4) of type (stream filter)

Warning: Object of class stdClass could not be converted to int in %s on line %d

Warning: fwrite(): Unprocessed filter buckets remaining on input brigade in %s on line %d
int(0)

Warning: Object of class stdClass could not be converted to int in Unknown on line 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
stream_filter_register() with a class name exist that mocks php_user_filter with a private filter method
--FILE--
<?php

class foo {
public $filtername;
public $params;

private function filter($in, $out, &$consumed, bool $closing): int {
return PSFS_PASS_ON;
}
}

var_dump(stream_filter_register("invalid_filter", "foo"));

var_dump(stream_filter_append(STDOUT, "invalid_filter"));

$out = fwrite(STDOUT, "Hello\n");
var_dump($out);

?>
--EXPECTF--
bool(true)
resource(%d) of type (stream filter)

Warning: fwrite(): Unprocessed filter buckets remaining on input brigade in %s on line %d

Fatal error: Uncaught Error: Invalid callback foo::filter, cannot access private method foo::filter() in %s:%d
Stack trace:
#0 %s(%d): fwrite(Resource id #%d, 'Hello\n')
#1 {main}
thrown in %s on line %d

Fatal error: Invalid callback foo::filter, cannot access private method foo::filter() in Unknown on line 0
Loading