Problem/Motivation

Getting this:
Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in custom_body_class_node_special_character_form_validate() (line 121 of modules/contrib/custom_body_class/custom_body_class.module).

Steps to reproduce

Install the Custom Body Class module and use it.

Proposed resolution

Add NULL checks to vars before passing to preg_match()

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    jaydee1818 created an issue. See original summary.

    atuliet05’s picture

    Assigned: Unassigned » atuliet05
    atuliet05’s picture

    Assigned: atuliet05 » Unassigned
    Status: Active » Reviewed & tested by the community

    I've applied the attached patch and tested this. The reported warning is no longer triggered.
    Marking this as RTBC.

    mosk’s picture

    I'm using drupal 10.3.1 (with PHP 8.3) and recently installed the Custom Body Class module via Composer. (https://www.drupal.org/project/custom_body_class)

    I am still getting the error below even after applying the patch ( https://www.drupal.org/project/custom_body_class/issues/3436902 ) whenever I try to add a custom class to the body of various content types.

    ERROR: Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in custom_body_class_node_special_character_form_validate() (line 121 of modules/contrib/custom_body_class/custom_body_class.module).

    jaroslav červený’s picture

    I test patch PHP 8.1.20 and Drupal 10.3.1
    and error is no longer.

    erwangel’s picture

    Patch worked for me.

    junaidpv’s picture

    Getting this warning when submitting node type edit form:

    Warning: Trying to access array offset on null in custom_body_class_node_special_character_form_validate() (line 118 of modules/contrib/custom_body_class/custom_body_class.module).

    Here is the improved patch.