Even safer version normalization
Peter Rabbitson [Thu, 8 Apr 2010 10:56:33 +0000 (10:56 +0000)]
lib/DBIx/Class/Storage/DBI.pm

index 655f506..f24a9e1 100644 (file)
@@ -950,11 +950,18 @@ sub _server_info {
       if (
         @verparts
           &&
-        @verparts <= 3
-          &&
-        ! grep { $_ > 999 } (@verparts)
+        $verparts[0] <= 999
       ) {
-        $info{normalized_dbms_version} = sprintf "%d.%03d%03d", @verparts;
+        # consider only up to 3 version parts, iff not more than 3 digits
+        my @use_parts;
+        while (@verparts && @use_parts < 3) {
+          my $p = shift @verparts;
+          last if $p > 999;
+          push @use_parts, $p;
+        }
+        push @use_parts, 0 while @use_parts < 3;
+
+        $info{normalized_dbms_version} = sprintf "%d.%03d%03d", @use_parts;
       }
     }