Commit 9a95bade authored by catch's avatar catch

Issue #3078001 by tedbow, Wim Leers: Don't catch exception for invalid...

Issue #3078001 by tedbow, Wim Leers: Don't catch exception for invalid 'core_version_requirement' in info.yml files
parent b015ba77
......@@ -16,29 +16,6 @@ class InfoParserDynamic implements InfoParserInterface {
*/
const FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION = '8.7.7';
/**
* Determines if a version satisfies the given constraints.
*
* This method uses \Composer\Semver\Semver::satisfies() but returns FALSE if
* the version or constraints are not valid instead of throwing an exception.
*
* @param string $version
* The version.
* @param string $constraints
* The constraints.
*
* @return bool
* TRUE if the version satisfies the constraints, otherwise FALSE.
*/
protected static function satisfies($version, $constraints) {
try {
return Semver::satisfies($version, $constraints);
}
catch (\UnexpectedValueException $exception) {
return FALSE;
}
}
/**
* {@inheritdoc}
*/
......@@ -82,20 +59,15 @@ public function parse($filename) {
// 'core_version_requirement' key. Do not throw the exception if the
// constraint also is satisfied by 8.0.0-alpha1 to allow constraints
// such as '^8' or '^8 || ^9'.
if ($supports_pre_core_version_requirement_version && !static::satisfies('8.0.0-alpha1', $parsed_info['core_version_requirement'])) {
if ($supports_pre_core_version_requirement_version && !Semver::satisfies('8.0.0-alpha1', $parsed_info['core_version_requirement'])) {
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");
}
}
// Determine if the extension is compatible with the current version of
// Drupal core.
try {
$core_version_constraint = isset($parsed_info['core_version_requirement']) ? $parsed_info['core_version_requirement'] : $parsed_info['core'];
$parsed_info['core_incompatible'] = !static::satisfies(\Drupal::VERSION, $core_version_constraint);
}
catch (\UnexpectedValueException $exception) {
$parsed_info['core_incompatible'] = TRUE;
}
$core_version_constraint = isset($parsed_info['core_version_requirement']) ? $parsed_info['core_version_requirement'] : $parsed_info['core'];
$parsed_info['core_incompatible'] = !Semver::satisfies(\Drupal::VERSION, $core_version_constraint);
if (isset($parsed_info['version']) && $parsed_info['version'] === 'VERSION') {
$parsed_info['version'] = \Drupal::VERSION;
}
......@@ -150,7 +122,7 @@ protected static function isConstraintSatisfiedByPreviousVersion($constraint, $v
if (!isset($evaluated_constraints[$constraint][$version])) {
$evaluated_constraints[$constraint][$version] = FALSE;
foreach (static::getAllPreviousCoreVersions($version) as $previous_version) {
if (static::satisfies($previous_version, $constraint)) {
if (Semver::satisfies($previous_version, $constraint)) {
$evaluated_constraints[$constraint][$version] = TRUE;
// The constraint only has to satisfy one previous version so break
// when the first one is found.
......
......@@ -428,11 +428,6 @@ public function providerCoreIncompatibility() {
"^1 || ^$next_major",
TRUE,
],
'invalid' => [
'invalid',
'this-string-is-invalid',
TRUE,
],
];
}
......@@ -459,4 +454,31 @@ public function testInvalidProfile() {
$this->infoParser->parse(vfsStream::url('profiles/fixtures/invalid_profile.info.txt'));
}
/**
* Tests the exception for an unparsable 'core_version_requirement' value.
*
* @covers ::parse
*/
public function testUnparsableCoreVersionRequirement() {
$unparsable_core_version_requirement = <<<UNPARSABLE_CORE_VERSION_REQUIREMENT
# info.yml for testing missing type key.
name: Not this module
description: 'Not the module you are looking for.'
package: Core
type: module
version: VERSION
core_version_requirement: not-this-version
UNPARSABLE_CORE_VERSION_REQUIREMENT;
vfsStream::setup('modules');
vfsStream::create([
'fixtures' => [
'unparsable_core_version_requirement.info.txt' => $unparsable_core_version_requirement,
],
]);
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Could not parse version constraint not-this-version: Invalid version string "not-this-version"');
$this->infoParser->parse(vfsStream::url('modules/fixtures/unparsable_core_version_requirement.info.txt'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment