deprecated strpos and PHP8.1 Compatibility

Created on 27 February 2023, about 2 years ago

Problem/Motivation

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php on line 301

Module have to be patched by replacing this

if (strpos($path, '//') === 0) {
      $path = '/' . ltrim($path, '/');
    }

by

if (strpos($path ?? '', '//') === 0) {
      $path = '/' . ltrim($path, '/');
    }
πŸ› Bug report
Status

Active

Version

9.5

Component
RoutingΒ  β†’

Last updated 2 days ago

Created by

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 @nicoc
  • Status changed to Postponed: needs info about 2 years ago
  • What is passing a null path?

  • This is just a proposition, cause i saw this solution many times with this kind of errors with PHP8.1

    $path = str_replace($this->decodedChars[0], $this->decodedChars[1], rawurlencode($path ?? ''));
    

    in fact, many lines of this have to be patched for php 8.1 .

    all these lines are not compatible with PHP8.1 :

    L301 if (strpos($path, '//') === 0) {
    L306 $path = str_replace($this->decodedChars[0], $this->decodedChars[1], rawurlencode($path));
    L309 if (strpos($path, '/.') !== FALSE) {
    L3016 if ('/..' === substr($path, -3)) {
    
    and more...
    

    The best way for me is to test $path before you use it.

  • First commit to issue fork.
  • Status changed to Closed: outdated 5 days ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Without steps to reproduce think this can be closed out. We run all MRs against 8.1 and 8.3, maybe even 8.4 now and if something was fully broken think we would find it. So would need steps for what could trigger this if there is an edge case. If steps can be provide feel free to re-open.

    Thanks all!

Production build 0.71.5 2024