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

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

$
0
0

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') {

Viewing all articles
Browse latest Browse all 294331

Trending Articles



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