Skip to content

Bug: [DebugBar] 4.5.0 TypeError: str_contains(): Argument #1 ($haystack) must be of type string, null given #8730

@iamsyh

Description

@iamsyh

PHP Version

8.2

CodeIgniter4 Version

4.5.0

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

Mysql 8

What happened?

When defining a custom filter in app/Config/Filters.php with specific URI patterns and using the codeigniter4/shield package for authentication, the Debug Toolbar throws a TypeError if the filter triggers a redirect. This issue seems to arise from how the Debug Toolbar processes responses, particularly when a controller or filter returns a non-standard response or null.

Screenshot 2024-04-09 at 03-37-37 TypeError

Steps to Reproduce

  1. In app/Config/Filters.php, define a before filter rule for specific paths, excluding some with a regex pattern, as shown below:
    public array $filters = [ 'session' => [ 'before' => [ '^myadminendpoint(?!/login|/register|/auth/a/)([a-zA-Z0-9/-]+)?$', ] ] ];
  2. Ensure the before filter (e.g., session filter from codeigniter4/shield) is configured to return a redirect under certain conditions.
  3. Access a URL that matches the filter's criteria and triggers the redirect.

Expected Output

The application should redirect to the specified location without any errors, even with the Debug Toolbar enabled.

Anything else?

Workaround

Temporarily removing the Debug Toolbar from the $globals and $required arrays in the after filters configuration resolves the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions