Problem/Motivation

\Drupal\dblog\Controller\DbLogController::createLink() can cause deprecations on PHP 8.1 because it passes NULLs to string functions.

Steps to reproduce

Run \Drupal\Tests\dblog\Functional\DbLogTest on PHP 8.1

Proposed resolution

Check $uri is not null before passing to UrlHelper::isValid()

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#3 3240182-2.patch626 bytesalexpott

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review

Here's the fix from the meta.

alexpott’s picture

StatusFileSize
new626 bytes
daffie’s picture

Status: Needs review » Reviewed & tested by the community

The value of $uri goes into a preg_match() function as the second parameter (in the method isValid()) and that must be a string in PHP 8.1.
Looks good to me.

catch’s picture

Status: Reviewed & tested by the community » Needs work

::createLink() is only called in two places, can we fix the callers instead?

dagmar’s picture

Status: Needs work » Reviewed & tested by the community

I think the approach in #3 is correct, given this is a bad use of the UrlHelper::isValid API (which expects a string). Also the method still does what the documentation of that method says it does.

But also inspecting the code of the UrlHelper there are other examples of methods that expect a string but does not specify the full type-hint. I guess this is what is discussed here #3050720: [Meta] Implement strict typing in existing code

andypost’s picture

@catch +1 RTBC as this protected method expects to deal with NULL as it documents in its doc-block

  • catch committed 09cf315 on 9.3.x
    Issue #3240182 by alexpott, daffie, dagmar, andypost: \Drupal\dblog\...
catch’s picture

Status: Reviewed & tested by the community » Fixed

OK, fair enough.

Committed 09cf315 and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.