Make WordPress Core

Opened 4 weeks ago

Last modified 4 days ago

#65870 accepted defect (bug)

wp_is_stream() should align with PHP stream handler matching

Reported by: jonsurrell Owned by: jonsurrell
Priority: normal Milestone: 7.2
Component: General Version: 3.5
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

wp_is_stream() performs exact (case-sensitive) matching against the results of stream_get_wrappers(). This differs from PHP, so PHP may handle some streams that wp_is_stream() reports as false.

When matching a scheme to a registered stream wrapper, PHP will check for an exact match, then check for a lower case match of the scheme against the registered stream wrappers. This has been the behavior since 4427552 which I believe shipped with PHP 5.2 and remains largely unchanged. wp_is_stream() fails to recognize some common streams if the scheme is not lowercase:

<?php
foreach ( array( 'file', 'FILE', 'fIlE' ) as $scheme ) {
  $f = "{$scheme}://" . php_ini_loaded_file();
  echo "{$f} / is_stream: " . var_export( wp_is_stream( $f ), true ) . " / strlen: " . strlen( file_get_contents( $f ) ) . "\n";
}
file:///internal/shared/php.ini / is_stream: true / strlen: 802
FILE:///internal/shared/php.ini / is_stream: false / strlen: 802
fIlE:///internal/shared/php.ini / is_stream: false / strlen: 802

Change History (4)

This ticket was mentioned in PR #13038 on WordPress/wordpress-develop by @khokansardar.


4 weeks ago
#1

  • Keywords has-patch has-unit-tests added

wp_is_stream() reports false for stream URLs whose scheme is not lowercase, such as FILE:///path/to/file, even though PHP opens and reads them without trouble.

PHP resolves a scheme by looking it up in the registered wrappers as given, then retrying once with the scheme lowercased; wp_is_stream() only did the exact match. The patch adds the same lowercased fallback. It deliberately does not lowercase the registered wrappers, so a wrapper registered as MyStream stays unreachable as mystream, matching PHP.

The accepted set only widens, so no path that returned true before can now return false.

Trac ticket: https://core.trac.wordpress.org/ticket/65870

## Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Reviewing PHP's stream wrapper lookup, drafting the fix, and adding regression tests. All changes were reviewed and validated by me.

#2 @jonsurrell
4 weeks ago

  • Version3.5

Introduced in r22094 as part of #6821, shipped in WordPress 3.5.

#3 @jonsurrell
5 days ago

  • Milestone Awaiting Review7.2
  • Owner set to jonsurrell
  • Status newaccepted

This ticket was mentioned in PR #13436 on WordPress/wordpress-develop by @jonsurrell.


4 days ago
#4

#WIP

Trac ticket:

## Use of AI Tools

Note: See TracTickets for help on using tickets.