]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 938300: vers_cmp() incorrectly compares module versions
authorFrédéric Buclin <LpSolit@gmail.com>
Mon, 2 Dec 2013 16:07:30 +0000 (17:07 +0100)
committerFrédéric Buclin <LpSolit@gmail.com>
Mon, 2 Dec 2013 16:07:30 +0000 (17:07 +0100)
r=sgreen a=justdave

Bugzilla/Install/Requirements.pm

index 78234151300c5a55fded65d1004d03e4ef04a7e1..2e67457abf34c85bd2d6ce7fe443b4d9abb2a10d 100644 (file)
@@ -24,6 +24,7 @@ package Bugzilla::Install::Requirements;
 # MUST NOT "use."
 
 use strict;
+use version;
 
 use Bugzilla::Constants;
 use Bugzilla::Install::Util qw(vers_cmp install_string bin_loc 
@@ -206,7 +207,9 @@ sub OPTIONAL_MODULES {
         package => 'Chart',
         module  => 'Chart::Lines',
         # Versions below 2.1 cannot be detected accurately.
-        version => '2.1',
+        # There is no 2.1.0 release (it was 2.1), but .0 is required to fix
+        # https://rt.cpan.org/Public/Bug/Display.html?id=28218.
+        version => '2.1.0',
         feature => [qw(new_charts old_charts)],
     },
     {
@@ -640,8 +643,8 @@ sub check_graphviz {
     return $return;
 }
 
-# This was originally clipped from the libnet Makefile.PL, adapted here to
-# use the below vers_cmp routine for accurate version checking.
+# This was originally clipped from the libnet Makefile.PL, adapted here for
+# accurate version checking.
 sub have_vers {
     my ($params, $output) = @_;
     my $module  = $params->{module};
@@ -666,21 +669,17 @@ sub have_vers {
     if ($@) {
         no strict 'refs';
         $vnum = ${"${module}::VERSION"};
-    }
-    $vnum ||= -1;
 
-    # CGI's versioning scheme went 2.75, 2.751, 2.752, 2.753, 2.76
-    # That breaks the standard version tests, so we need to manually correct
-    # the version
-    if ($module eq 'CGI' && $vnum =~ /(2\.7\d)(\d+)/) {
-        $vnum = $1 . "." . $2;
-    }
-    # CPAN did a similar thing, where it has versions like 1.9304.
-    if ($module eq 'CPAN' and $vnum =~ /^(\d\.\d{2})\d{2}$/) {
-        $vnum = $1;
+        # If we come here, then the version is not a valid one.
+        # We try to sanitize it.
+        if ($vnum =~ /^((\d+)(\.\d+)*)/) {
+            $vnum = $1;
+        }
     }
+    $vnum ||= -1;
 
-    my $vok = (vers_cmp($vnum,$wanted) > -1);
+    # Must do a string comparison as $vnum may be of the form 5.10.1.
+    my $vok = ($vnum ne '-1' && version->new($vnum) >= version->new($wanted)) ? 1 : 0;
     my $blacklisted;
     if ($vok && $params->{blacklist}) {
         $blacklisted = grep($vnum =~ /$_/, @{$params->{blacklist}});