[SCM] dpkg's main repository branch, master, updated. 1.16.0-7-g0cacb0c

2011-04-03 Thread Raphaël Hertzog
The following commit has been merged in the master branch:
commit fa98524b587fd1d8c376c00cbd5175d1c197
Author: Raphaël Hertzog hert...@debian.org
Date:   Sun Apr 3 09:45:20 2011 +0200

libdpkg: add non-regression test for version number starting with non-digit

And update the non-regression test for invalid characters to put
the invalid character as the second character and not the first (which
would be caught by the more strict non-digit check).

diff --git a/lib/dpkg/test/t-version.c b/lib/dpkg/test/t-version.c
index 2e52781..9975084 100644
--- a/lib/dpkg/test/t-version.c
+++ b/lib/dpkg/test/t-version.c
@@ -141,10 +141,13 @@ test_version_parse(void)
test_fail(parseversion(a, a:0-0) == NULL);
test_fail(parseversion(a, A:0-0) == NULL);
 
+   /* Test upstream version not starting with a digit */
+   test_fail(parseversion(a, 0:abc3-0) == NULL);
+
/* Test invalid characters in upstream version. */
-   verstr = m_strdup(0:0-0);
+   verstr = m_strdup(0:0a-0);
for (p = !#@$%/|\\()[]{};,_=*^'; *p; p++) {
-   verstr[2] = *p;
+   verstr[3] = *p;
test_fail(parseversion(a, verstr) == NULL);
}
free(verstr);

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



[SCM] dpkg's main repository branch, master, updated. 1.16.0-7-g0cacb0c

2011-04-03 Thread Raphaël Hertzog
The following commit has been merged in the master branch:
commit 0cacb0c3a1d1f837c957f3917a040ace6d60f9e7
Author: Raphaël Hertzog hert...@debian.org
Date:   Sun Apr 3 09:52:33 2011 +0200

Dpkg::Version: update version_check to forbid versions starting with non 
digits

Adapted the code to rely on the parsing done by the constructor to split
the version number properly instead of redoing similar regexes in
version_check().

Updated the test suite accordingly.

diff --git a/scripts/Dpkg/Version.pm b/scripts/Dpkg/Version.pm
index f0f7cd2..9f0f3a1 100644
--- a/scripts/Dpkg/Version.pm
+++ b/scripts/Dpkg/Version.pm
@@ -88,7 +88,7 @@ sub new {
 }
 
 my $self = {};
-if ($ver =~ /^(\d*):(.+)$/) {
+if ($ver =~ /^([^:]*):(.+)$/) {
$self-{'epoch'} = $1;
$ver = $2;
 } else {
@@ -159,7 +159,7 @@ sub comparison {
 $b = Dpkg::Version-new($b);
 }
 ($a, $b) = ($b, $a) if $inverted;
-my $r = $a-epoch() = $b-epoch();
+my $r = version_compare_part($a-epoch(), $b-epoch());
 return $r if $r;
 $r = version_compare_part($a-version(), $b-version());
 return $r if $r;
@@ -362,22 +362,29 @@ contains a description of the problem with the $version 
scalar.
 
 sub version_check($) {
 my $version = shift;
-$version = $version if ref($version);
-
-if (not defined($version) or not length($version)) {
+my $str;
+if (defined $version) {
+$str = $version;
+$version = Dpkg::Version-new($str) unless ref($version);
+}
+if (not defined($str) or not length($str)) {
 my $msg = _g(version number cannot be empty);
 return (0, $msg) if wantarray;
 return 0;
 }
-if ($version =~ m/([^-+:.0-9a-zA-Z~])/o) {
+if ($version-version() =~ m/^[^\d]/) {
+my $msg = _g(version number does not start with digit);
+return (0, $msg) if wantarray;
+return 0;
+}
+if ($str =~ m/([^-+:.0-9a-zA-Z~])/o) {
 my $msg = sprintf(_g(version number contains illegal character 
`%s'), $1);
 return (0, $msg) if wantarray;
 return 0;
 }
-if ($version =~ /:/ and $version !~ /^\d*:/) {
-$version =~ /^([^:]*):/;
+if ($version-epoch() !~ /^\d*$/) {
 my $msg = sprintf(_g(epoch part of the version number  .
- is not a number: '%s'), $1);
+ is not a number: '%s'), $version-epoch());
 return (0, $msg) if wantarray;
 return 0;
 }
diff --git a/scripts/t/100_Dpkg_Version.t b/scripts/t/100_Dpkg_Version.t
index 0f4926d..97bc7d2 100644
--- a/scripts/t/100_Dpkg_Version.t
+++ b/scripts/t/100_Dpkg_Version.t
@@ -28,7 +28,7 @@ my @ops = (, , lt,
   =, ge,
   , , gt);
 
-plan tests = scalar(@tests) * (3 * scalar(@ops) + 4) + 11;
+plan tests = scalar(@tests) * (3 * scalar(@ops) + 4) + 13;
 
 sub dpkg_vercmp {
  my ($a, $cmp, $b) = @_;
@@ -87,6 +87,10 @@ ok($ver eq '10a:5.2', invalid still same string 1/2);
 $ver = Dpkg::Version-new('5.2@3-2');
 ok($ver eq '5.2@3-2', invalid still same string 2/2);
 ok(!$ver-is_valid(), illegal character is invalid);
+$ver = Dpkg::Version-new('foo5.2');
+ok(!$ver-is_valid(), version does not start with digit 1/2);
+$ver = Dpkg::Version-new('0:foo5.2');
+ok(!$ver-is_valid(), version does not start with digit 2/2);
 
 # Other tests
 $ver = Dpkg::Version-new('1.2.3-4');

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org