Commit f78790cb authored by catch's avatar catch
Browse files

fix: #3567483 Update manager crashing admin panel with uncaught exceptions parsing version strings

By: cassius
By: longwave
By: jpoesen
By: cmlara
By: catch
By: dww
By: jastraat
(cherry picked from commit 09ebcac3)
parent 83bd4be8
Loading
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -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;
@@ -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';
    });
@@ -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;
        }
+7 −0
Original line number Diff line number Diff line
@@ -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;
  }