Quellcode durchsuchen

Fix Dpkg::Version comparison code. Closes: #504135

* scripts/Dpkg/Version.pm: Synchronize code with version used by
debbugs (add some bugfixes).
* scripts/t/900_Dpkg_Version.t: Add non-regression tests for
version comparison code.
* scripts/Makefile.am: Add new file in the dist tarball.
Raphael Hertzog vor 17 Jahren
Ursprung
Commit
e9a8d2b52f
5 geänderte Dateien mit 102 neuen und 4 gelöschten Zeilen
  1. 8 0
      ChangeLog
  2. 1 0
      debian/changelog
  3. 3 3
      scripts/Dpkg/Version.pm
  4. 2 1
      scripts/Makefile.am
  5. 88 0
      scripts/t/900_Dpkg_Version.t

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2008-11-07  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/Dpkg/Version.pm: Synchronize code with version used by
+	debbugs (add some bugfixes).
+	* scripts/t/900_Dpkg_Version.t: Add non-regression tests for
+	version comparison code.
+	* scripts/Makefile.am: Add new file in the dist tarball.
+
 2008-10-20  Raphael Hertzog  <hertzog@debian.org>
 
 	* scripts/Dpkg/Shlibs/SymbolFile.pm (load): Let the recursively

+ 1 - 0
debian/changelog

@@ -6,6 +6,7 @@ dpkg (1.14.23) UNRELEASED; urgency=low
   * Important bugfix in dpkg-gensymbols for people using includes in symbol
     files: the current object didn't flow back from the included file to
     the including file.
+  * Fix Dpkg::Version comparison code. Closes: #504135
 
   [ Updated dpkg translations ]
   * Greek (Emmanuel Galatoulas). Closes: #498585

+ 3 - 3
scripts/Dpkg/Version.pm

@@ -59,7 +59,7 @@ sub parseversion ($)
     {
 	$verhash{epoch} = 0;
     }
-    if ($ver =~ /(.+)-(.+)$/)
+    if ($ver =~ /(.+)-(.*)$/)
     {
 	$verhash{version} = $1;
 	$verhash{revision} = $2;
@@ -90,7 +90,7 @@ sub verrevcmp($$)
 	  #           : (x) + 256)
 	  # This comparison is out of dpkg's order to avoid
 	  # comparing things to undef and triggering warnings.
-	  if (not defined $x) {
+	  if (not defined $x or not length $x) {
 	       return 0;
 	  }
 	  elsif ($x eq '~') {
@@ -140,7 +140,7 @@ sub verrevcmp($$)
 	  }
 	  return 1 if defined $vc and $vc =~ /^\d$/;
 	  return -1 if defined $rc and $rc =~ /^\d$/;
-	  return $first_diff if $first_diff;
+	  return (($first_diff  > 0) ? 1 : -1) if $first_diff;
      }
      return 0;
 }

+ 2 - 1
scripts/Makefile.am

@@ -78,7 +78,8 @@ EXTRA_DIST = \
 	t/600_Dpkg_Changelog/shadow \
 	t/700_Dpkg_Control.t \
 	t/700_Dpkg_Control/control-1 \
-	t/800_Dpkg_IPC.t
+	t/800_Dpkg_IPC.t \
+	t/900_Dpkg_Version.t
 
 CLEANFILES = \
 	$(bin_SCRIPTS) $(sbin_SCRIPTS) $(changelog_SCRIPTS) \

+ 88 - 0
scripts/t/900_Dpkg_Version.t

@@ -0,0 +1,88 @@
+# -*- mode: cperl;-*-
+
+use Test::More;
+
+use strict;
+use warnings;
+
+my @tests = <DATA>;
+my @ops = ("<", "<<", "lt",
+	   "<=", "le",
+	   "=", "eq",
+	   ">=", "ge",
+	   ">", ">>", "gt");
+
+plan tests => scalar(@tests) * (scalar(@ops) + 1) + 1;
+
+use_ok('Dpkg::Version', qw(vercmp compare_versions));
+
+my $truth = {
+    "-1" => {
+	"<" => 1, "<<" => 1, "lt" => 1,
+	"<=" => 1, "le" => 1,
+	"=" => 0, "eq" => 0,
+	">=" => 0, "ge" => 0,
+	">" => 0, ">>" => 0, "gt" => 0,
+    },
+    "0" => {
+	"<" => 0, "<<" => 0, "lt" => 0,
+	"<=" => 1, "le" => 1,
+	"=" => 1, "eq" => 1,
+	">=" => 1, "ge" => 1,
+	">" => 0, ">>" => 0, "gt" => 0,
+    },
+    "1" => {
+	"<" => 0, "<<" => 0, "lt" => 0,
+	"<=" => 0, "le" => 0,
+	"=" => 0, "eq" => 0,
+	">=" => 1, "ge" => 1,
+	">" => 1, ">>" => 1, "gt" => 1,
+    },
+};
+
+foreach my $case (@tests) {
+    my ($a, $b, $res) = split " ", $case;
+    is(vercmp($a, $b), $res, "$a cmp $b => $res");
+    foreach my $op (@ops) {
+	if ($truth->{$res}{$op}) {
+	    ok(compare_versions($a, $op, $b), "$a $op $b => true");
+	} else {
+	    ok(!compare_versions($a, $op, $b), "$a $op $b => false");
+	}
+    }
+}
+
+__DATA__
+1:foo foo 1
+0:foo foo 0
+foo foo 0
+foo- foo 0
+foo fo 1
+foo- foo+ -1
+foo~1 foo -1
+foo~foo+Bar foo~foo+bar -1
+foo~~ foo~ -1
+12345+that-really-is-some-ver-0 12345+that-really-is-some-ver-10 -1
+foo-0 foo-01 -1
+foo.bar foobar 1
+foo.bar foo1bar 1
+foo.bar foo0bar 1
+1foo-1 foo-1 -1
+foo2.0 foo2 1
+foo2.0.0 foo2.10.0 -1
+foo2.0 foo2.0.0 -1
+foo2.0 foo2.10 -1
+foo2.1 foo2.10 -1
+1.09 1.9 0
+1.0.8+nmu1 1.0.8 1
+3.11 3.10+nmu1 1
+0.9j-20080306-4 0.9i-20070324-2 1
+1.2.0~b7-1 1.2.0~b6-1 1
+1.011-1 1.06-2 1
+0.0.9+dfsg1-1 0.0.8+dfsg1-3 1
+4.6.99+svn6582-1 4.6.99+svn6496-1 1
+53 52 1
+0.9.9~pre122-1 0.9.9~pre111-1 1
+2:2.3.2-2+lenny2 2:2.3.2-2 1
+1:3.8.1-1 3.8.GA-1 1
+1.0.1+gpl-1 1.0.1-2 1