diff --git a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php index 2e1dae399d..76628913c6 100644 --- a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php +++ b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php @@ -73,9 +73,6 @@ public function parse($filename) { throw new InfoParserException("The 'core' or the 'core_version_requirement' key must be present in " . $filename); } } - if (isset($parsed_info['core']) && !preg_match("/^\d\.x$/", $parsed_info['core'])) { - throw new InfoParserException("Invalid 'core' value \"{$parsed_info['core']}\" in " . $filename); - } if (isset($parsed_info['core_version_requirement'])) { $supports_pre_core_version_requirement_version = static::isConstraintSatisfiedByPreviousVersion($parsed_info['core_version_requirement'], static::FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION); // If the 'core_version_requirement' constraint does not satisfy any @@ -94,6 +91,17 @@ public function parse($filename) { throw new InfoParserException("The 'core_version_requirement' can not be used to specify compatibility for a specific version before " . static::FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION . " in $filename"); } } + if (isset($parsed_info['core'])) { + if (!preg_match("/^\d\.x$/", $parsed_info['core'])) { + throw new InfoParserException("Invalid 'core' value \"{$parsed_info['core']}\" in " . $filename); + } + if ($parsed_info['core'] === '9.x') { + if (!isset($parsed_info['core_version_requirement'])) { + throw new InfoParserException("'core: 9.x' is not supported. Use 'core_version_requirement' to specify core compatibility in " . $filename); + } + throw new InfoParserException("'core: 9.x' is not supported. 'core_version_requirement' is used to specify core compatibility in " . $filename); + } + } // Determine if the extension is compatible with the current version of // Drupal core. diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index 2e8c9ce1ca..d33d4dea0f 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -274,6 +274,86 @@ public function testInvalidCore() { } } + /** + * Tests 'core: 9.x' which is not needed. + * + * @covers ::parse + */ + public function testNotNeededCore() { + $not_needed_core = << [ + 'not_needed_core.info.txt' => $not_needed_core, + 'not_needed_core-duplicate.info.txt' => $not_needed_core, + ], + ]); + $exception_message = "'core: 9.x' is not supported. 'core_version_requirement' is used to specify core compatibility in vfs://modules/fixtures/not_needed_core%s.info.txt"; + // Set the expected exception for the 2nd call to parse(). + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage(sprintf($exception_message, '-duplicate')); + + try { + $this->infoParser->parse(vfsStream::url('modules/fixtures/not_needed_core.info.txt')); + } + catch (InfoParserException $exception) { + $this->assertSame(sprintf($exception_message, ''), $exception->getMessage()); + + $this->infoParser->parse(vfsStream::url('modules/fixtures/not_needed_core-duplicate.info.txt')); + } + } + + /** + * Tests a invalid 'core' key. + * + * @covers ::parse + */ + public function testCore9x() { + $not_needed_core = << [ + 'not_needed_core.info.txt' => $not_needed_core, + 'not_needed_core-duplicate.info.txt' => $not_needed_core, + ], + ]); + $exception_message = "'core: 9.x' is not supported. Use 'core_version_requirement' to specify core compatibility in vfs://modules/fixtures/not_needed_core%s.info.txt"; + // Set the expected exception for the 2nd call to parse(). + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage(sprintf($exception_message, '-duplicate')); + + try { + $this->infoParser->parse(vfsStream::url('modules/fixtures/not_needed_core.info.txt')); + } + catch (InfoParserException $exception) { + $this->assertSame(sprintf($exception_message, ''), $exception->getMessage()); + + $this->infoParser->parse(vfsStream::url('modules/fixtures/not_needed_core-duplicate.info.txt')); + } + } + /** * Tests a invalid 'core_version_requirement'. *