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
11 changes: 9 additions & 2 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7494,6 +7494,7 @@ function _device_can_upload() {
* Tests if a given path is a stream URL
*
* @since 3.5.0
* @since 7.2.0 A lowercased scheme is accepted as a fallback, matching PHP.
*
* @param string $path The resource path or URL.
* @return bool True if the path is a stream URL.
Expand All @@ -7506,9 +7507,15 @@ function wp_is_stream( $path ) {
return false;
}

$stream = substr( $path, 0, $scheme_separator );
$stream = substr( $path, 0, $scheme_separator );
$wrappers = stream_get_wrappers();

return in_array( $stream, stream_get_wrappers(), true );
/*
* PHP looks the scheme up as given, then retries once with it lowercased.
* This is not a case-insensitive match: a wrapper registered as `MyStream`
* is not reachable as `mystream`.
*/
return in_array( $stream, $wrappers, true ) || in_array( strtolower( $stream ), $wrappers, true );
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,8 @@ public function data_validate_file() {
/**
* Test stream URL validation.
*
* @ticket 65870
*
* @dataProvider data_wp_is_stream
*
* @param string $path The resource path or URL.
Expand Down Expand Up @@ -2037,6 +2039,7 @@ public function data_wp_is_stream() {
array( 'https://example.com', true ),
array( 'ftp://example.com', true ),
array( 'file:///path/to/some/file', true ),
array( 'FILE:///path/to/some/file', true ),
array( 'php://some/php/file.php', true ),

// Non-stream examples.
Expand All @@ -2047,6 +2050,25 @@ public function data_wp_is_stream() {
);
}

/**
* Tests that a wrapper registered under a mixed case scheme is not
* reachable under a lowercased scheme.
*
* @ticket 65870
*/
public function test_wp_is_stream_does_not_lowercase_registered_wrappers() {
require_once DIR_TESTROOT . '/includes/class-wp-test-stream.php';
stream_wrapper_register( 'wpTestMixedCase', 'WP_Test_Stream' );

$exact = wp_is_stream( 'wpTestMixedCase://foo' );
$lowercased = wp_is_stream( 'wptestmixedcase://foo' );

stream_wrapper_unregister( 'wpTestMixedCase' );

$this->assertTrue( $exact, 'The scheme was not matched as registered.' );
$this->assertFalse( $lowercased, 'A lowercased scheme matched a mixed case wrapper.' );
}

/**
* Test human_readable_duration().
*
Expand Down
Loading