This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=23802ae9be9760a4135b8ca2911c86045fe47fc2 commit 23802ae9be9760a4135b8ca2911c86045fe47fc2 Author: Guillem Jover <[email protected]> AuthorDate: Sun Oct 21 22:55:29 2018 +0200 Dpkg::Source::Package: Improve debian/source/format parsing and validation Make the regex more strict and decompose it right away instead of doing a second pass over it. Only initialize minor when we need to update the format. And fix the error for an invalid format to stop referencing the Format field, which might not be involved during the parsing. --- debian/changelog | 2 ++ scripts/Dpkg/Source/Package.pm | 25 +++++++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/debian/changelog b/debian/changelog index 63c983e4b..6065bc48d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,8 @@ dpkg (1.19.3) UNRELEASED; urgency=medium - Dpkg::Source::Package::V3::Bzr: Fix format name in output message. - Dpkg::Source::Package: Add a new format option to the new constructor. Prompted by James McCoy <[email protected]>. + - Dpkg::Source::Package: Improve debian/source/format parsing and + validation. * Documentation: - dpkg(1): Clarify --remove action. Closes: #914478 - dpkg-query(1): Clarify --list option behavior when no arguments are diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm index b3a80ba1d..29e61170e 100644 --- a/scripts/Dpkg/Source/Package.pm +++ b/scripts/Dpkg/Source/Package.pm @@ -290,16 +290,8 @@ sub upgrade_object_type { $self->{fields}{'Format'} //= '1.0'; my $format = $self->{fields}{'Format'}; - if ($format =~ /^([\d\.]+)(?:\s+\((.*)\))?$/) { - my ($version, $variant) = ($1, $2); - - if (defined $variant and $variant ne lc $variant) { - error(g_("source package format '%s' is not supported: %s"), - $format, g_('format variant must be in lowercase')); - } - - my $major = $version =~ s/\.[\d\.]+$//r; - my $minor; + if ($format =~ /^(\d+)(?:\.(\d+))?(?:\s+\(([a-z0-9]+)\))?$/) { + my ($major, $minor, $variant) = ($1, $2, $3); my $module = "Dpkg::Source::Package::V$major"; $module .= '::' . ucfirst $variant if defined $variant; @@ -308,19 +300,20 @@ sub upgrade_object_type { require $module; \$minor = \$${module}::CURRENT_MINOR_VERSION; }; - $minor //= 0; - if ($update_format) { - $self->{fields}{'Format'} = "$major.$minor"; - $self->{fields}{'Format'} .= " ($variant)" if defined $variant; - } if ($@) { error(g_("source package format '%s' is not supported: %s"), $format, $@); } + + if ($update_format) { + $minor //= 0; + $self->{fields}{'Format'} = "$major.$minor"; + $self->{fields}{'Format'} .= " ($variant)" if defined $variant; + } $module->prerequisites() if $module->can('prerequisites'); bless $self, $module; } else { - error(g_("invalid Format field '%s'"), $format); + error(g_("source package format '%s' is invalid"), $format); } } -- Dpkg.Org's dpkg

