Fix GH-15155: Keep stream context in filtered streams

Closes GH-15156
This commit is contained in:
Quentin Dreyer 2024-07-29 17:47:17 +02:00 committed by Jakub Zelenka
parent af8ef4c5b0
commit 7b32a145d9
No known key found for this signature in database
GPG key ID: 1C0779DC5C0A9DE4
3 changed files with 42 additions and 1 deletions

4
NEWS
View file

@ -37,6 +37,10 @@ PHP NEWS
- Standard:
. Unserializing the uppercase 'S' tag is now deprecated. (timwolla)
- Streams:
. Implemented GH-15155 (Stream context is lost when custom stream wrapper is
being filtered). (Quentin Dreyer)
01 Aug 2024, PHP 8.4.0alpha4
- GMP:

View file

@ -352,7 +352,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
return NULL;
}
if (!(stream = php_stream_open_wrapper(p + 10, mode, options, opened_path))) {
if (!(stream = php_stream_open_wrapper_ex(p + 10, mode, options, opened_path, context))) {
efree(pathdup);
return NULL;
}

View file

@ -0,0 +1,37 @@
--TEST--
GH-15155: Stream context is lost when custom stream wrapper is being filtered
--FILE--
<?php
class DummyWrapper
{
public $context;
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool
{
$options = stream_context_get_options($this->context);
var_dump($options['dummy']['foo']);
return true;
}
public function stream_stat()
{
}
public function stream_read()
{
}
public function stream_eof()
{
}
}
$context = stream_context_create(['dummy' => ['foo' => 'bar']]);
stream_wrapper_register('dummy', DummyWrapper::class);
file_get_contents('dummy://foo', false, $context);
@file_get_contents('php://filter/resource=dummy://foo', false, $context);
?>
--EXPECT--
string(3) "bar"
string(3) "bar"