Skip to content

Code assumes that installer-paths elements are _always_ arrays #59

Description

@diegoe

The current code assumes that elements are always arrays:

if (is_array($json)) {
if (isset($json['extra']['installer-paths']) && is_array($json['extra']['installer-paths'])) {
foreach ($json['extra']['installer-paths'] as $install_path => $items) {
if (in_array('type:drupal-core', $items) ||
in_array('drupal/core', $items) ||
in_array('drupal/drupal', $items)) {

However, upstream "allows" simple strings by casting to array:

https://github.com/composer/installers/blob/2a9170263fcd9cc4fd0b50917293c21d6c1a5bfe/src/Composer/Installers/BaseInstaller.php#L116-L119

Predictably, this causes a crash:

PHP Fatal error:  Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in  /webflo/drupal-finder/src/DrupalFinder.php:113
Stack trace:
#0 webflo/drupal-finder/src/DrupalFinder.php(113): in_array('type:drupal-cor...', 'a-module-name-im-using...')

Whether to follow upstream or not, it would be best to avoid the crash since strings instead of arrays is "not wrong" (?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions