From 9c049f7ecc35e4c16c1ef717e5f07f17ebdc50dd Mon Sep 17 00:00:00 2001 From: Andy Postnikov Date: Thu, 7 Jul 2022 21:27:26 +0200 Subject: [PATCH] Fix preg_match() usage when looking for extension type https://www.php.net/manual/en/splfileobject.fgets.php may return False --- src/Drupal/ExtensionDiscovery.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Drupal/ExtensionDiscovery.php b/src/Drupal/ExtensionDiscovery.php index 483f08d2..33017600 100644 --- a/src/Drupal/ExtensionDiscovery.php +++ b/src/Drupal/ExtensionDiscovery.php @@ -377,9 +377,11 @@ protected function scanDirectory($dir): array $type = false; $file = $fileinfo->openFile('r'); while (!$type && !$file->eof()) { - preg_match('@^type:\s*(\'|")?(\w+)\1?\s*$@', $file->fgets(), $matches); - if (isset($matches[2])) { - $type = $matches[2]; + if ($line = $file->fgets()) { + preg_match('@^type:\s*(\'|")?(\w+)\1?\s*$@', $line, $matches); + if (isset($matches[2])) { + $type = $matches[2]; + } } } if ($type === false) {