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

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

Closed
iamsyh opened this issue Apr 8, 2024 · 3 comments · Fixed by #8727
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@iamsyh
Copy link
Contributor

iamsyh commented Apr 8, 2024

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.

@iamsyh iamsyh added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 8, 2024
@iamsyh iamsyh changed the title Bug: Debugtoolbar inside $required causes issues with before session filter of auth Bug: 4.5.0 Interaction Issues Between Custom Filters and Debug Toolbar When Using codeigniter4/shield Apr 8, 2024
@kenjis
Copy link
Member

kenjis commented Apr 8, 2024

Try #8727

@kenjis kenjis changed the title Bug: 4.5.0 Interaction Issues Between Custom Filters and Debug Toolbar When Using codeigniter4/shield Bug: [DebugBar] 4.5.0 Interaction Issues Between Custom Filters and Debug Toolbar When Using codeigniter4/shield Apr 8, 2024
@kenjis kenjis changed the title Bug: [DebugBar] 4.5.0 Interaction Issues Between Custom Filters and Debug Toolbar When Using codeigniter4/shield Bug: [DebugBar] 4.5.0 TypeError: str_contains(): Argument #1 ($haystack) must be of type string, null given Apr 8, 2024
@kenjis kenjis pinned this issue Apr 8, 2024
@DPComp
Copy link

DPComp commented Apr 11, 2024

When will this be online in master for download / update?

@samsonasik
Copy link
Member

It will done when it done.

You can use develop branch while wait for new release https://codeigniter.com/user_guide/installation/installing_composer.html#latest-dev and help us give more feedback in case of any regression.

@kenjis kenjis unpinned this issue Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants