From 86d0cbbb25e6517031c491ff443f9685e65df84d Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Tue, 1 Jan 2008 14:54:55 +0100 Subject: [PATCH] Dpkg::Version: Add check_version to replace controllib's checkversion * scripts/Dpkg/Version.pm (check_version): New function. * scripts/dpkg-buildpackage.pl: Use the new check_version. * scripts/dpkg-source.pl: Likewise. --- ChangeLog | 5 +++++ scripts/Dpkg/Version.pm | 13 ++++++++++++- scripts/dpkg-buildpackage.pl | 3 ++- scripts/dpkg-source.pl | 5 +++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index deaa9252..fa122b14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -36,6 +36,11 @@ to use the new modules Dpkg::Cdata, Dpkg::Control, Dpkg::Fields::Object and Dpkg::Substvars. + * scripts/Dpkg/Version.pm (check_version): New function replacing + checkversion of controllib.pl. + * scripts/dpkg-source.pl, scripts/dpkg-buildpackage.pl: Use the + new check_version. + 2007-12-28 Raphael Hertzog * scripts/Dpkg/ErrorHandling.pm (syntaxerr): New function to diff --git a/scripts/Dpkg/Version.pm b/scripts/Dpkg/Version.pm index 406f707a..937558a1 100644 --- a/scripts/Dpkg/Version.pm +++ b/scripts/Dpkg/Version.pm @@ -23,7 +23,7 @@ use warnings; use Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(vercmp compare_versions); +our @EXPORT_OK = qw(vercmp compare_versions check_version); =head1 NAME @@ -192,6 +192,17 @@ sub compare_versions ($$$) } } +=item check_version($version) + +Check the version string and fails it it's invalid. + +=cut +sub check_version ($) { + my $version = shift || ''; + $version =~ m/[^-+:.0-9a-zA-Z~]/o && + error(_g("version number contains illegal character `%s'"), $&); +} + =back =head1 AUTHOR diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl index 9d07efa3..a21c5af1 100755 --- a/scripts/dpkg-buildpackage.pl +++ b/scripts/dpkg-buildpackage.pl @@ -11,6 +11,7 @@ use Dpkg::Gettext; use Dpkg::ErrorHandling qw(warning error failure syserr subprocerr usageerr $warnable_error); use Dpkg::BuildOptions; +use Dpkg::Version qw(check_version); push (@INC, $dpkglibdir); require 'controllib.pl'; @@ -283,7 +284,7 @@ sub mustsetvar { my $pkg = mustsetvar($changes{source}, _g('source package')); my $version = mustsetvar($changes{version}, _g('source version')); -checkversion($version); +check_version($version); my $maintainer; if ($changedby) { diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index 142c94c5..2cbbd292 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -15,6 +15,7 @@ use Dpkg::Compression; use Dpkg::Cdata; use Dpkg::Control; use Dpkg::Substvars; +use Dpkg::Version qw(check_version); my @filesinarchive; my %dirincluded; @@ -385,7 +386,7 @@ if ($opmode eq 'build') { if (m/^Source$/) { setsourcepackage($v); } elsif (m/^Version$/) { - checkversion( $v ); + check_version($v); $fields->{$_} = $v; } elsif (s/^X[BS]*C[BS]*-//i) { $fields->{$_} = $v; @@ -865,7 +866,7 @@ if ($opmode eq 'build') { my $baseversion; my $revision; - checkversion( $version ); + check_version($version); $version =~ s/^\d+://; if ($version =~ m/-([^-]+)$/) { $baseversion= $`; $revision= $1; -- 2.39.5