forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug77069.phpt
57 lines (47 loc) · 1.58 KB
/
bug77069.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--TEST--
Bug #77069 (stream filter loses final block of data)
--FILE--
<?php
class MyFilter extends php_user_filter {
private $data = '';
public function filter($in, $out, &$consumed, $closing): int {
$return = PSFS_FEED_ME;
// While input data is available, continue to read it.
while ($bucket_in = stream_bucket_make_writeable($in)) {
$this->data .= $bucket_in->data;
$consumed += $bucket_in->datalen;
// Process whole lines.
while (preg_match('/(.*?)[\r\n]+(.*)/s', $this->data, $match) === 1) {
list(, $data, $this->data) = $match;
// Send this record output.
$data = strrev($data) . PHP_EOL;
$bucket_out = stream_bucket_new($this->stream, $data);
$return = PSFS_PASS_ON;
stream_bucket_append($out, $bucket_out);
}
}
// Process the final line.
if ($closing && $this->data !== '') {
$data = strrev($this->data) . PHP_EOL;
$bucket_out = stream_bucket_new($this->stream, $data);
$return = PSFS_PASS_ON;
stream_bucket_append($out, $bucket_out);
}
return $return;
}
}
stream_filter_register('my-filter', 'MyFilter');
$input = "Line one\nLine two\nLine three";
$stream = fopen('data://text/plain,' . $input, 'r');
stream_filter_append($stream, 'my-filter');
$output = '';
while (!feof($stream)) {
$output .= fread($stream, 16);
}
fclose($stream);
echo $output;
?>
--EXPECT--
eno eniL
owt eniL
eerht eniL