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

Make sure format() returns string. #1439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jonpugh
Copy link

@jonpugh jonpugh commented Aug 22, 2023

I am getting a strange failure when testing some old Drupal code:

TypeError: Behat\Behat\Output\Printer\Formatter\ConsoleFormatter::format(): Return value must be of type string, null returned in Behat\Behat\Output\Printer\Formatter\ConsoleFormatter->format() (line 33 of /usr/share/devshop/src/DevShop/Control/vendor/behat/behat/src/Behat/Behat/Output/Printer/Formatter/ConsoleFormatter.php).

Looking into it, I discovered format() calls preg_replace_callback, which returns null|string|string[].

This change returns an empty string if preg_replace_callback returns null.

Should we check for an array as well?

preg_replace_callback returns null|string|string[].

This change checks for null. 

Should we check for an array as well?
@stof
Copy link
Member

stof commented Aug 23, 2023

Can you share a reproducer for a case making the regex fail ?

@stof
Copy link
Member

stof commented Aug 23, 2023

Should we check for an array as well?

No. preg_replace_callback returns an array when its subject argument is an array, which is not the case here.

@mdio
Copy link

mdio commented Nov 6, 2023

I ran into this when the response body (which was checked) was generated by https://github.com/filp/whoops due to an exception being thrown. Unfortunately I cannot share the content because it's full of internal information.
The HTML was 1 MB large with a 6 level stack trace and roughly a thousand environment variables.
The error for preg_replace_callback was PREG_BACKTRACK_LIMIT_ERROR with pcre.backtrack_limit being 1000000 (the default).

I believe issue #1431 is about the same problem.

Maybe this helps to craft a test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants