[PHP 8] [Metatag module] Module incorrectly assumes string, triggering PHP 8 fatal error

Created on 19 April 2023, over 1 year ago
Updated 21 April 2023, over 1 year ago

Problem/Motivation

The current code includes a check for a noindex value in the metatags robots element using strpos, but this element can be an array. PHP 8 has stricter type checking than PHP 7, so this mismatch in the use of strpos triggers a fatal error. which can lead to a page crash:

TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in strpos() (line 2574 of xmlsitemap.module)

This problem is present on both the 8.x-1.x-dev branch and 2.x

Steps to reproduce

1. Site is running on PHP 8
2. The contrib module "Metatag" is installed and enabled on a content type that also has XMLSitemap enabled.
3. Upon trying to save a node, the PHP error above will be produced.

Proposed resolution

Provide a legacy check for the string value of noindex and provide a new check for the array value of the Robots metatag value.

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

🇺🇸United States mark_fullmer Tucson

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

Comments & Activities

Production build 0.71.5 2024