preg_match() Passing null to parameter #2 ($subject) of type string is deprecated.

Created on 4 March 2025, about 1 month ago

Problem/Motivation

After the update to CSP 1.33 we get a warning on the pregmatch for sometimes containg null values in the source, we should filter these out these null values and not parse them to the preg match.

Steps to reproduce

Visit any admin page on 1.33 and see that the preg_match is giving these warning, when error logs are enabled.

Proposed resolution

Review patch and create merge request.

Remaining tasks

Review patch and create merge request.

User interface changes

none

API changes

none

Data model changes

none

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇱Netherlands Remco Hoeneveld

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Remco Hoeneveld
  • 🇳🇱Netherlands Remco Hoeneveld

    Above is a simple solution to fix the errors in the logs.

    Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\csp\Csp::Drupal\csp\{closure}() (line 507 of modules/contrib/csp/src/Csp.php).
    
  • 🇨🇦Canada gapple

    Do you have a custom module altering the policy values, or is this reproducible by just configuring the CSP module?

    Null values are not expected to be passed to setDirective or appendDirective, and are likely to cause type errors or assertion failures on CSP 2.x, so should be addressed in any code calling those methods to avoid issues when upgrading.

  • 🇳🇱Netherlands Remco Hoeneveld

    Thank for the reply, ill check thanks for the explanation!

Production build 0.71.5 2024