Skip to content

Commit

Permalink
Autoloader: Avoid a PHP warning when an empty string is passed to `is…
Browse files Browse the repository at this point in the history
…_directory_plugin()`. (#16442)

Co-authored-by: Brandon Kraft <[email protected]>
  • Loading branch information
dd32 and kraftbj authored Jul 9, 2020
1 parent a8106ed commit 2927b61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit 2927b61

Please sign in to comment.