Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297110

setting path alias to `/` causes PHP8.1/str_starts_with/null error

$
0
0

Problem/Motivation

Setting an url alias to `/` causes a deprecated notice in PHP 8.1. Internally it seems to be converted to an empty string or null.

```
Deprecated function: str_starts_with(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\path_alias\PathProcessor\AliasPathProcessor->processOutbound() (line 54 of core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php).
```

Motivation to set url alias to a single slash is to generate proper canonical and alternate links, e. g.:

```html

<link rel="canonical" href="http://localhost:8000/node/1" />
<link rel="shortlink" href="http://localhost:8000/node/1" />

```

should become:

```html

<link rel="canonical" href="http://localhost:8000" />
<link rel="shortlink" href="http://localhost:8000/node/1" />

```

Or in a multilingual setup:

```html

<link rel="shortlink" href="http://localhost:8000/de" />
<link rel="canonical" href="http://localhost:8000/de" />
<link rel="alternate" hreflang="de" href="http://localhost:8000/de" />
<link rel="alternate" hreflang="en" href="http://localhost:8000/en" />

```

Related issue: https://www.drupal.org/project/drupal/issues/3308707

Steps to reproduce

Drupal: 10.1.5
PHP: 8.1

```bash
mkdir test
cd test
composer create-project drupal/recommended-project .
composer require drush/drush
```

* create `README.md`, `docker-compose.yml`, `.env` manually
* `docker-compose up -d`, `docker exec -it drupal bash`
* `drush site:install`, type drupal config
* add `$config['system.logging']['error_level'] = 'verbose';` to `web/sites/default/settings.php`
* open browser, login
* create basic page, set url alias to `/`, save page
* error message pops up on all page loads

Proposed resolution

Add `if (!$path) $path = '';` in `core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php` after line 47

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 297110

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>