backdrop-issues icon indicating copy to clipboard operation
backdrop-issues copied to clipboard

Deprecation / better optimization for backdrop_match_path()?

Open laryn opened this issue 10 months ago • 1 comments

Description of the bug

I'm seeing this warning on a site that I'm working on locally:

Deprecated function: preg_quote(): Passing null to parameter #1 ($str) of type string is deprecated in backdrop_match_path() (line 311 of /var/www/vhosts/sotp/live/core/includes/path.inc).

Steps To Reproduce

I'm still looking for ways to reproduce with a minimal installation.

Actual behavior

Deprecated warning is generated due to a deprecation.

Expected behavior

Deprecation is not triggered and no warning is generated.

Additional information

This may be due to the Domain module as I haven't seen it elsewhere and the site I'm looking at locally is a D7 upgrade that is using Domain. That said, in looking at backdrop_match_path() it seems we may be able to just skip processing if no patterns exist (ie. if $patterns is empty) and avoid this whole deprecation, which occurs further down when $patterns is submitted to preg_quote.

Backdrop 1.30.0 PHP 8.1.x

laryn avatar Jan 28 '25 18:01 laryn

You could have an early return of false if $patterns is null, or not a string.

herbdool avatar Feb 03 '25 12:02 herbdool

Line 311 is this line:

    $patterns_quoted = preg_quote($patterns, '/');

Which indicates to me that backdrop_match_path($path, $patterns) is being called with $patterns being a NULL value. I think the correct fix here would be to find the calling code, and make sure that $patterns is a string, not NULL.

Some day we may start enforcing types on parameters (i.e. change the function signature to function backdrop_match_path(string $path, string $patterns), which would throw an error if NULL is passed in. So I think it's better that this is fixed in the calling code.

quicksketch avatar Mar 22 '25 06:03 quicksketch