diff --git a/includes/module.inc b/includes/module.inc index 8fd4273ef0780f75c3692d9e54921371a761fa00..ffdb4c1651a549277fdcb09ac1c809d5f6eca023 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -102,7 +102,7 @@ function _module_build_dependencies($files) { $p_core = '(?:' . preg_quote(DRUPAL_CORE_COMPATIBILITY) . '-)?'; $p_major = '(?P<major>\d+)'; // By setting the minor version to x, branches can be matched. - $p_minor = '(?P<minor>\d+|x)'; + $p_minor = '(?P<minor>(?:\d+|x)(?:-[A-Za-z]+\d+)?)'; foreach ($files as $filename => $file) { $graph[$file->name]['edges'] = array(); if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) { @@ -116,17 +116,14 @@ function _module_build_dependencies($files) { if (preg_match("/^\s*$p_op\s*$p_core$p_major\.$p_minor/", $version, $matches)) { $op = !empty($matches['operation']) ? $matches['operation'] : '='; if ($matches['minor'] == 'x') { - // If a module is newer than 2.x then it's at least 3.0. - $matches['minor'] = 0; - if ($op == '>') { + // Drupal considers "2.x" to mean any version that begins with + // "2" (e.g. 2.0, 2.9 are all "2.x"). PHP's version_compare(), + // on the other hand, treats "x" as a string; so to + // version_compare(), "2.x" is considered less than 2.0. This + // means that >=2.x and <2.x are handled by version_compare() + // as we need, but > and <= are not. + if ($op == '>' || $op == '<=') { $matches['major']++; - $op = '>='; - } - // If a module is older or equivalent than 2.x then it is older - // than 3.0. - if ($op == '<=') { - $matches['major']++; - $op = '<'; } // Equivalence is checked by preg. if ($op == '=' || $op == '==') { diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module index cab3b9e57d51ca63a6f5ac5eb11d66f82dd923a7..3f0a1acef9517c4a8d488f2da6ef32c70607268b 100644 --- a/modules/simpletest/tests/system_test.module +++ b/modules/simpletest/tests/system_test.module @@ -180,7 +180,7 @@ function system_test_system_info_alter(&$info, $file) { } if ($file->name == 'common_test') { $info['hidden'] = FALSE; - $info['version'] = '7.x-2.4'; + $info['version'] = '7.x-2.4-beta3'; } } } diff --git a/modules/system/system.test b/modules/system/system.test index 48526c7354a2c3ab0c8e704786799c4549b5cbf0..738d3119bb02c8f906d82dacf1f25f0ed02b91b2 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -208,7 +208,7 @@ class ModuleVersionTestCase extends ModuleTestCase { 'group' => 'Module', ); } - + function setup() { parent::setUp('module_test'); } @@ -218,7 +218,7 @@ class ModuleVersionTestCase extends ModuleTestCase { */ function testModuleVersions() { $dependencies = array( - // Alternating between being compatible and incompatible with 7.x-2.4. + // Alternating between being compatible and incompatible with 7.x-2.4-beta3. // The first is always a compatible. 'common_test', // Branch incompatibility. @@ -236,11 +236,17 @@ class ModuleVersionTestCase extends ModuleTestCase { // Nonsense, misses a dash. Incompatible with everything. 'common_test (=7.x2.x, >=2.4)', // Core version is optional. Compatible. - 'common_test (=7.x-2.x, >=2.4)', + 'common_test (=7.x-2.x, >=2.4-alpha2)', // Test !=, explicitly incompatible. - 'common_test (=2.x, !=2.4)', + 'common_test (=2.x, !=2.4-beta3)', // Three operations. Compatible. 'common_test (=2.x, !=2.3, <2.5)', + // Testing extra version. Incompatible. + 'common_test (<=2.4-beta2)', + // Testing extra version. Compatible. + 'common_test (>2.4-beta2)', + // Testing extra version. Incompatible. + 'common_test (>2.4-rc0)', ); variable_set('dependencies', $dependencies); $n = count($dependencies);