Loading core/modules/update/src/ProjectCoreCompatibility.php +23 −4 Original line number Diff line number Diff line Loading @@ -86,7 +86,15 @@ protected function getPossibleCoreUpdateVersions(array $core_releases, array $su // versions after the existing version. return []; } $supported_versions = array_filter(array_keys($core_releases), function ($version) use ($supported_branches) { $version_parser = new VersionParser(); $supported_versions = array_filter(array_keys($core_releases), function ($version) use ($supported_branches, $version_parser) { // Filter out invalid semantic versions from external sources. try { $version_parser->normalize($version); } catch (\UnexpectedValueException) { return FALSE; } foreach ($supported_branches as $supported_branch) { if (strpos($version, $supported_branch) === 0) { return TRUE; Loading @@ -94,8 +102,13 @@ protected function getPossibleCoreUpdateVersions(array $core_releases, array $su } return FALSE; }); try { $possible_core_update_versions = Semver::satisfiedBy($supported_versions, '>= ' . $this->existingCoreVersion); $possible_core_update_versions = Semver::sort($possible_core_update_versions); } catch (\UnexpectedValueException) { return []; } $possible_core_update_versions = array_filter($possible_core_update_versions, function ($version) { return VersionParser::parseStability($version) === 'stable'; }); Loading Loading @@ -218,7 +231,13 @@ protected function createMessageFromCoreCompatibility($core_compatibility_constr protected function getCompatibilityRanges($core_compatibility_constraint) { $compatibility_ranges = []; foreach ($this->possibleCoreUpdateVersions as $possible_core_update_version) { if (Semver::satisfies($possible_core_update_version, $core_compatibility_constraint)) { try { $satisfies = Semver::satisfies($possible_core_update_version, $core_compatibility_constraint); } catch (\UnexpectedValueException) { continue; } if ($satisfies) { if (empty($range)) { $range[] = $possible_core_update_version; } Loading core/modules/update/tests/src/Unit/ProjectCoreCompatibilityTest.php +7 −0 Original line number Diff line number Diff line Loading @@ -159,6 +159,13 @@ public static function providerSetProjectCoreCompatibilityRanges() { 'core_compatibility_message' => 'Requires Drupal core: 8.9.0, 8.9.2, 9.0.1 to 9.0.2', ], ]; // Ensure that invalid version strings like "main" are filtered out and // do not cause exceptions. $test_cases['with invalid version string in releases'] = $test_cases['with 9 full releases, supported']; $test_cases['with invalid version string in releases']['supported_branches'][] = 'main'; $test_cases['with invalid version string in releases']['core_releases']['main'] = []; return $test_cases; } Loading Loading
core/modules/update/src/ProjectCoreCompatibility.php +23 −4 Original line number Diff line number Diff line Loading @@ -86,7 +86,15 @@ protected function getPossibleCoreUpdateVersions(array $core_releases, array $su // versions after the existing version. return []; } $supported_versions = array_filter(array_keys($core_releases), function ($version) use ($supported_branches) { $version_parser = new VersionParser(); $supported_versions = array_filter(array_keys($core_releases), function ($version) use ($supported_branches, $version_parser) { // Filter out invalid semantic versions from external sources. try { $version_parser->normalize($version); } catch (\UnexpectedValueException) { return FALSE; } foreach ($supported_branches as $supported_branch) { if (strpos($version, $supported_branch) === 0) { return TRUE; Loading @@ -94,8 +102,13 @@ protected function getPossibleCoreUpdateVersions(array $core_releases, array $su } return FALSE; }); try { $possible_core_update_versions = Semver::satisfiedBy($supported_versions, '>= ' . $this->existingCoreVersion); $possible_core_update_versions = Semver::sort($possible_core_update_versions); } catch (\UnexpectedValueException) { return []; } $possible_core_update_versions = array_filter($possible_core_update_versions, function ($version) { return VersionParser::parseStability($version) === 'stable'; }); Loading Loading @@ -218,7 +231,13 @@ protected function createMessageFromCoreCompatibility($core_compatibility_constr protected function getCompatibilityRanges($core_compatibility_constraint) { $compatibility_ranges = []; foreach ($this->possibleCoreUpdateVersions as $possible_core_update_version) { if (Semver::satisfies($possible_core_update_version, $core_compatibility_constraint)) { try { $satisfies = Semver::satisfies($possible_core_update_version, $core_compatibility_constraint); } catch (\UnexpectedValueException) { continue; } if ($satisfies) { if (empty($range)) { $range[] = $possible_core_update_version; } Loading
core/modules/update/tests/src/Unit/ProjectCoreCompatibilityTest.php +7 −0 Original line number Diff line number Diff line Loading @@ -159,6 +159,13 @@ public static function providerSetProjectCoreCompatibilityRanges() { 'core_compatibility_message' => 'Requires Drupal core: 8.9.0, 8.9.2, 9.0.1 to 9.0.2', ], ]; // Ensure that invalid version strings like "main" are filtered out and // do not cause exceptions. $test_cases['with invalid version string in releases'] = $test_cases['with 9 full releases, supported']; $test_cases['with invalid version string in releases']['supported_branches'][] = 'main'; $test_cases['with invalid version string in releases']['core_releases']['main'] = []; return $test_cases; } Loading