diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 05f1e4f..b040c18 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -677,12 +677,14 @@ public static function parseDependency($dependency) { $p_major = '(?\d+)'; // By setting the minor version to x, branches can be matched. $p_minor = '(?(?:\d+|x)(?:-[A-Za-z]+\d+)?)'; + // @todo@ if $p_minor is 'x', then there's no patch version for sure. Since we don't support 8.x.1 and 8.x.x is redundant with core compatibility check. + $p_patch = '(?(?:\d+|x)(?:-[A-Za-z]+\d+)?)'; $parts = explode('(', $dependency, 2); $value['name'] = trim($parts[0]); if (isset($parts[1])) { $value['original_version'] = ' (' . $parts[1]; foreach (explode(',', $parts[1]) as $version) { - if (preg_match("/^\s*$p_op\s*$p_core$p_major\.$p_minor/", $version, $matches)) { + if (preg_match("/^\s*$p_op\s*$p_core$p_major\.$p_minor(\.$p_patch)?/", $version, $matches)) { $op = !empty($matches['operation']) ? $matches['operation'] : '='; if ($matches['minor'] == 'x') { // Drupal considers "2.x" to mean any version that begins with @@ -700,7 +702,11 @@ public static function parseDependency($dependency) { $op = '>='; } } - $value['versions'][] = array('op' => $op, 'version' => $matches['major'] . '.' . $matches['minor']); + $version = $matches['major'] . '.' . $matches['minor']; + if (isset($matches['patch'])) { + $version .= '.' . $matches['patch']; + } + $value['versions'][] = array('op' => $op, 'version' => $version); } } } diff --git a/core/modules/system/src/Tests/Module/DependencyTest.php b/core/modules/system/src/Tests/Module/DependencyTest.php index e9162a8..a57ba23 100644 --- a/core/modules/system/src/Tests/Module/DependencyTest.php +++ b/core/modules/system/src/Tests/Module/DependencyTest.php @@ -82,6 +82,21 @@ function testIncompatibleModuleVersionDependency() { } /** + * Tests enabling a module that depends on an incompatible semantic version of a module. + */ + function testIncompatibleModuleSemanticVersionDependency() { + // Test that the system_incompatible_module_semantic_version_dependencies_test is + // marked as having an incompatible dependency. + $this->drupalGet('admin/modules'); + $this->assertRaw(t('@module (incompatible with version @version)', array( + '@module' => 'System (>= 8.1.999)', + '@version' => \Drupal::VERSION, + )), 'A module that depends on an incompatible semantic version of a module is marked as such.'); + $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[Testing][system_incompatible_module_semantic_version_dependencies_test][enable]"]'); + $this->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.'); + } + + /** * Tests enabling a module that depends on a module with an incompatible core version. */ function testIncompatibleCoreVersionDependency() { diff --git a/core/modules/system/tests/modules/system_incompatible_module_semantic_version_dependencies_test/system_incompatible_module_semantic_version_dependencies_test.info.yml b/core/modules/system/tests/modules/system_incompatible_module_semantic_version_dependencies_test/system_incompatible_module_semantic_version_dependencies_test.info.yml new file mode 100644 index 0000000..4a1a72d --- /dev/null +++ b/core/modules/system/tests/modules/system_incompatible_module_semantic_version_dependencies_test/system_incompatible_module_semantic_version_dependencies_test.info.yml @@ -0,0 +1,8 @@ +name: 'System incompatible module semantic version dependencies test' +type: module +description: 'Support module for testing system dependencies.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - 'drupal:system (>= 8.1.999)'