Drupal core 7.98 preg_match() function error on php 8.1

Created on 31 October 2023, 11 months ago
Updated 7 November 2023, 11 months ago

Drupal core 7.98
PHP version 8.1

preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in drupal_match_path() (line 331 of /var/www/html/docroot/includes/path.inc).

🐛 Bug report
Status

Postponed: needs info

Version

7.0 ⚰️

Component
Routing 

Last updated 1 day ago

Created by

🇮🇳India arif.zisu Kolkata

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

  • Issue created by @arif.zisu
  • Status changed to Active 11 months ago
  • 🇮🇳India arif.zisu Kolkata

    Hi @Cilefen,
    I am getting this error from my drupal watchdog files.

  • 🇮🇳India arif.zisu Kolkata

    Hi ,

    I have applied below patch to fix this

    index 5ed4a4ce..95951d5e 100644
    --- a/docroot/includes/path.inc
    +++ b/docroot/includes/path.inc
    @@ -328,7 +328,7 @@ function drupal_match_path($path, $patterns) {
         $patterns_quoted = preg_quote($patterns, '/');
         $regexps[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
       }
    -  return (bool)preg_match($regexps[$patterns], $path);
    +  return (bool)preg_match($regexps[$patterns], (string) $path);
     }
    
     /**
    
    
  • Status changed to Needs work 11 months ago
  • Status changed to Postponed: needs info 11 months ago
  • 🇸🇰Slovakia poker10

    The drupal_match_path() is called only 4x in Drupal 7 core (not counting the tests):

    2x in path_is_admin() with argument current_path() (aka $_GET['q']), which cannot be empty/NULL.

    2x in block_block_list_alter()
    - the second one is using $_GET['q'] as well, which cannot be NULL.
    - the first one is using drupal_get_path_alias($_GET['q']), but if this was the case, then you will end up with different error, as the result is used in drupal_strtolower() which also does not accept NULLs.

    So I think this is caused by some contrib module/custom code . As @cilefen pointed out in #4, please provide more information (like backtrace, or steps to reproduce), so that we can do anything here. Thanks!

Production build 0.71.5 2024