Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoloader: Avoid a PHP warning when an empty string is passed to is_directory_plugin(). #16442

Merged
merged 2 commits into from
Jul 9, 2020
Merged
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
2 changes: 1 addition & 1 deletion packages/autoloader/src/class-plugins-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function create_plugin_path( $plugin_slug ) {
* @return bool
*/
public function is_directory_plugin( $plugin ) {
return false !== strpos( $plugin, '/', 1 );
return strlen( $plugin ) > 1 && false !== strpos( $plugin, '/', 1 );
}

/**
Expand Down
9 changes: 9 additions & 0 deletions packages/autoloader/tests/php/test_plugins_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public function test_is_directory_plugin_single_file() {
$this->assertFalse( $this->plugins_handler->is_directory_plugin( 'test.php' ) );
}

/**
* Tests is_directory_plugin() with an empty string.
*
* @covers Plugins_Handler::is_directory_plugin
*/
public function test_is_directory_plugin_single_file_with_empty_string() {
$this->assertFalse( $this->plugins_handler->is_directory_plugin( '' ) );
}

/**
* Tests is_directory_plugin() with a single-file plugin that begins with '/'.
*
Expand Down