Problem/Motivation

analyze code the first time:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /batch?id=22&op=do_nojs&op=do
StatusText: error
ResponseText: The website encountered an unexpected error. Try again later.

TypeError: count(): Argument #1 ($value) must be of type Countable|array, false given in count() (line 1201 of ..../vendor/drupal-code-builder/drupal-code-builder/Task/Collect/PluginTypesCollector.php).

env:
Drupal: 11.4.5
module_builder: 4.2.6
Shared hosting

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lblabr created an issue. See original summary.

saurabhkanva made their first commit to this issue’s fork.

gurkawal’s picture

Hi

I have reproduced the issue on drupal 11.4 and php 8.4.
When executing the Module Builder code analysis task (/admin/config/development/module_builder/analyse), an AJAX 500 error occurs :
TypeError: count(): Argument #1 ($value) must be of type Countable|array, false given

The problem was caused by plugin IDs and service IDs being used directly inside regular expressions. If those values contain regex special characters, preg_grep() can fail or return unexpected results, which can break the schema prefix detection.

I have prepared a patch that fixes this by escaping the dynamic values with preg_quote() before using them in the regex. It also adds checks to safely skip processing when preg_grep() does not return a valid result.

I tested the change locally and confirmed that the plugin schema collection works correctly without the previous warnings/errors.

Patch attached for review and testing.

gurkawal’s picture

Status: Active » Needs review
nitinkumar_7’s picture

Add a regression test with a plugin ID containing regex characters, e.g. `foo.bar` or `foo+bar`, and verify the correct config schema is detected.
Also cover an unmatched/invalid regex case to confirm `preg_grep()` returning `false` no longer causes a `count(false)` TypeError.

nitinkumar_7’s picture

And could you please open a follow-up MR

joachim’s picture

Status: Needs review » Postponed (maintainer needs more info)

> The problem was caused by plugin IDs and service IDs being used directly inside regular expressions. If those values contain regex special characters

Good catch, but I'm curious about what plugin IDs and service IDs can contain that's dangerous for a regex! They're always a-z_. so surely the . would just match itself?

I can't reproduce this on core 11.4.5, so presumably this is a misbehaving contrib or custom module. Which modules were you running in addition to core?

> if (empty($candidate_schema_ids) || !is_array($candidate_schema_ids)) {

This is needless -- if the return of preg_grep() is not an array, it's FALSE, and the empty() will already have caught it.

lblabr’s picture

ho do i may support here?

lblabr’s picture

#17 .../httpdocs/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#18 .../httpdocs/modules/contrib/simple_oauth/src/HttpMiddleware/BasicAuthSwap.php(54): Symfony\Component\HttpKernel\HttpKernel->handle()

fails here ?