Notice: Uninitialized string offset: 0 in Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension()

Created on 17 February 2023, over 1 year ago
Updated 2 March 2023, over 1 year ago

Problem/Motivation

When a library version is defined as a string, we get the notice: Notice: Uninitialized string offset: 0 in Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension() (line 145 of /core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php

Steps to reproduce

Enable the dblog module

Install any contrib module (such as devel) or in any custom module that have a library.yml file defining a version with a integer/string such as version: 0.

Check your dblog report, and you should have a record similar to:

Notice: Uninitialized string offset: 0 in Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension() (line 145 of /web/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php) 

Proposed resolution

The current code on LibraryDiscoveryParser.php checks for $library['version'][0] without prior checking if the array index exists.

I'm proposing to update that elseif statement to first check if the array index exists.

Original code:

elseif (is_string($library['version']) && $library['version'][0] === 'v') {

Proposed code:

elseif (is_string($library['version']) && isset($library['version'][0]) && $library['version'][0] === 'v') {
πŸ› Bug report
Status

Needs work

Version

9.5

Component
Asset libraryΒ  β†’

Last updated 2 days ago

No maintainer
Created by

πŸ‡§πŸ‡·Brazil yuriseki

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

Comments & Activities

Production build 0.69.0 2024