Package: lintian Version: 2.5.10 Severity: wishlist Tags: patch >From 65a8aa5012589e7ca44eaa51c4adc7874dcbfefa Mon Sep 17 00:00:00 2001 From: "Bernhard R. Link" <[email protected]> Date: Mon, 16 Jul 2012 13:20:24 +0200 Subject: [PATCH] c/fields: check vcs URLs for unexpected spaces and old URLs
add %VCS_EXTRACT with subrotines to split a VCS-* field into it's components. Warn against unaccounted spaces (i.e. currently only allow one optional module with cvs, a mandatory module name with monotone and an optional " -b " with git). warn if a URL would cause redirections or port forwards or is otherwise uncanonical or outdated. Signed-off-by: Bernhard R. Link <[email protected]> --- checks/fields | 79 ++++++++++++++++++-- checks/fields.desc | 14 ++++ .../debian/debian/control.in | 1 + t/tests/fields-malformed-vcs-fields/desc | 1 + t/tests/fields-malformed-vcs-fields/tags | 1 + .../debian/debian/control.in | 22 ++++++ t/tests/fields-uncanonical-vcs-fields/desc | 6 ++ t/tests/fields-uncanonical-vcs-fields/tags | 6 ++ t/tests/fields-vcs-fields/debian/debian/control.in | 12 +-- t/tests/fields-vcs-fields/desc | 2 + 10 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 t/tests/fields-uncanonical-vcs-fields/debian/debian/control.in create mode 100644 t/tests/fields-uncanonical-vcs-fields/desc create mode 100644 t/tests/fields-uncanonical-vcs-fields/tags diff --git a/checks/fields b/checks/fields index 69bb103..570b07a 100644 --- a/checks/fields +++ b/checks/fields @@ -103,6 +103,54 @@ my @NAME_SECTION_MAPPINGS = ( [ qr/^lib.*-dev$/ => 'libdevel' ], ); +my %VCS_EXTRACT = ( + browser => sub { return @_;}, + arch => sub { return @_;}, + bzr => sub { return @_;}, + # cvs rootdir followed by optional module name: + cvs => sub { return shift =~ /^(.+?)(?:\s+(\S*))?$/;}, + darcs => sub { return @_;}, + hg => sub { return @_;}, + # git uri followed by optional " -b " + branchname: + git => sub { return shift =~ /^(.+?)(?:\s+-b\s+(\S*))?$/;}, + svn => sub { return @_;}, + # that's a hostname followed by a module name: + mtn => sub { return shift =~ /^(.+?)\s+(\S+)$/;}, +); +my %VCS_CANONIFY = ( + browser => sub { + $_[0] =~ s{https?://svn.debian.org/wsvn/}{http://anonscm.debian.org/viewvc/}; + $_[0] =~ s{http://git.debian.org/\?p=}{http://anonscm.debian.org/gitweb/?p=}; + $_[0] =~ s{http://bzr.debian.org/loggerhead/}{http://anonscm.debian.org/loggerhead/}; + }, + cvs => sub { + $_[0] =~ s{\@cvs.alioth.debian.org:/cvsroot/}{\@anonscm.debian.org:/cvs/}; + $_[0] =~ s{\@cvs.alioth.debian.org:/cvs/}{\@anonscm.debian.org:/cvs/}; + $_[0] =~ s{\@anonscm.debian.org:/cvsroot/}{\@anonscm.debian.org:/cvs/}; + }, + arch => sub { + $_[0] =~ s{http://arch.debian.org/arch/}{http://anonscm.debian.org/arch/}; + }, + bzr => sub { + $_[0] =~ s{http://bzr.debian.org/}{http://anonscm.debian.org/bzr/}; + $_[0] =~ s{http://anonscm.debian.org/bzr/bzr/}{http://anonscm.debian.org/bzr/}; + }, + git => sub { + $_[0] =~ s{http://git.debian.org/}{http://anonscm.debian.org/git/}; + $_[0] =~ s{http://anonscm.debian.org/git/git/}{http://anonscm.debian.org/git/}; + $_[0] =~ s{git://git.debian.org/}{git://anonscm.debian.org/}; + $_[0] =~ s{git://anonscm.debian.org/git/}{git://anonscm.debian.org/}; + }, + hg => sub { + $_[0] =~ s{http://hg.debian.org/}{http://anonscm.debian.org/hg/}; + $_[0] =~ s{http://anonscm.debian.org/hg/hg/}{http://anonscm.debian.org/hg/}; + }, + svn => sub { + $_[0] =~ s{svn://cvs.alioth.debian.org/}{svn://anonscm.debian.org/}; + $_[0] =~ s{svn://svn.debian.org/}{svn://anonscm.debian.org/}; + $_[0] =~ s{svn://anonscm.debian.org/svn/}{svn://anonscm.debian.org/}; + }, +); # Valid URI formats for the Vcs-* fields # currently only checks the protocol, not the actual format of the URI my %VCS_RECOMMENDED_URIS = ( @@ -114,7 +162,7 @@ my %VCS_RECOMMENDED_URIS = ( hg => qr;^https?://;, git => qr;^(?:git|https?|rsync)://;, svn => qr;^(?:svn|(?:svn\+)?https?)://;, - mtn => qr;^[\w.-]+\s+\S+;, # that's a hostname followed by a module name + mtn => qr;^[\w.-]+$;, ); my %VCS_VALID_URIS = ( arch => qr;^https?://;, @@ -939,15 +987,32 @@ if (defined $info->field('dm-upload-allowed')) { #----- Vcs-* -while (my ($vcs, $regex) = each %VCS_RECOMMENDED_URIS) { +while (my ($vcs, $splitter) = each %VCS_EXTRACT) { if (defined $info->field("vcs-$vcs")) { my $uri = $info->field("vcs-$vcs"); unfold("vcs-$vcs", \$uri); - if ($uri !~ $regex) { - if ($VCS_VALID_URIS{$vcs} and $uri =~ $VCS_VALID_URIS{$vcs}) { - tag 'vcs-field-uses-not-recommended-uri-format', "vcs-$vcs", $uri; - } else { - tag 'vcs-field-uses-unknown-uri-format', "vcs-$vcs", $uri; + my @parts = &$splitter($uri); + if (not @parts or not $parts[0]) { + tag 'vcs-field-uses-unknown-uri-format', "vcs-$vcs", $uri; + } else { + if ($VCS_RECOMMENDED_URIS{$vcs} and $parts[0] !~ $VCS_RECOMMENDED_URIS{$vcs}) { + if ($VCS_VALID_URIS{$vcs} and $parts[0] =~ $VCS_VALID_URIS{$vcs}) { + tag 'vcs-field-uses-not-recommended-uri-format', "vcs-$vcs", $uri; + } else { + tag 'vcs-field-uses-unknown-uri-format', "vcs-$vcs", $uri; + } + } + if (grep { $_ and /\s/} @parts) { + tag 'vcs-field-has-unexpected-spaces', "vcs-$vcs", $uri; + } + } + if ($VCS_CANONIFY{$vcs}) { + my $canonicalized = $parts[0]; + foreach my $canonify ($VCS_CANONIFY{$vcs}) { + &$canonify($canonicalized); + } + if ($canonicalized ne $parts[0]) { + tag 'vcs-field-not-canonical', $parts[0], $canonicalized; } } } diff --git a/checks/fields.desc b/checks/fields.desc index 94d1fde..80aad42 100644 --- a/checks/fields.desc +++ b/checks/fields.desc @@ -985,6 +985,20 @@ Certainty: possible Info: The VCS-* field uses an URI which doesn't match any known format. You might have forgotten the protocol before the hostname. +Tag: vcs-field-has-unexpected-spaces +Severity: normal +Certainty: possible +Info: The VCS-* field contains more spaces than expected or spaces at + places where they were not expected. Where possible escape valid spaces + in URIs to avoid any ambiguity with respect to possible future additional + optional fields. + +Tag: vcs-field-not-canonical +Severity: minor +Certainty: possible +Info: The VCS-* field contains an uncanonical URI. Please update to use + the current canonical URI instead. + Tag: lib-recommends-documentation Severity: normal Certainty: possible diff --git a/t/tests/fields-malformed-vcs-fields/debian/debian/control.in b/t/tests/fields-malformed-vcs-fields/debian/debian/control.in index 8b1b1a8..ba1e113 100644 --- a/t/tests/fields-malformed-vcs-fields/debian/debian/control.in +++ b/t/tests/fields-malformed-vcs-fields/debian/debian/control.in @@ -6,6 +6,7 @@ Standards-Version: {$standards_version} Build-Depends: debhelper (>= 9) Vcs-Browser: svn.debian.org/wsvn/foobar/trunk Vcs-Svn: svn+ssh://svn.debian.org/svn/foobar/trunk +Vcs-Git: git://anonscm.debian.org/test/test.git --branch wrong Package: {$srcpkg} Architecture: {$architecture} diff --git a/t/tests/fields-malformed-vcs-fields/desc b/t/tests/fields-malformed-vcs-fields/desc index 5157ddd..8dc829c 100644 --- a/t/tests/fields-malformed-vcs-fields/desc +++ b/t/tests/fields-malformed-vcs-fields/desc @@ -5,3 +5,4 @@ Version: 1.0 Test-For: vcs-field-uses-not-recommended-uri-format vcs-field-uses-unknown-uri-format + vcs-field-has-unexpected-spaces diff --git a/t/tests/fields-malformed-vcs-fields/tags b/t/tests/fields-malformed-vcs-fields/tags index 3fdeb6b..d7d432b 100644 --- a/t/tests/fields-malformed-vcs-fields/tags +++ b/t/tests/fields-malformed-vcs-fields/tags @@ -1,2 +1,3 @@ I: fields-malformed-vcs-fields source: vcs-field-uses-not-recommended-uri-format vcs-svn svn+ssh://svn.debian.org/svn/foobar/trunk +W: fields-malformed-vcs-fields source: vcs-field-has-unexpected-spaces vcs-git git://anonscm.debian.org/test/test.git --branch wrong W: fields-malformed-vcs-fields source: vcs-field-uses-unknown-uri-format vcs-browser svn.debian.org/wsvn/foobar/trunk diff --git a/t/tests/fields-uncanonical-vcs-fields/debian/debian/control.in b/t/tests/fields-uncanonical-vcs-fields/debian/debian/control.in new file mode 100644 index 0000000..c37d538 --- /dev/null +++ b/t/tests/fields-uncanonical-vcs-fields/debian/debian/control.in @@ -0,0 +1,22 @@ +Source: {$srcpkg} +Priority: extra +Section: {$section} +Maintainer: {$author} +Standards-Version: {$standards_version} +Build-Depends: debhelper (>= 9) +Vcs-Browser: https://svn.debian.org/wsvn/foobar/trunk +Vcs-Svn: svn://svn.debian.org/svn/foobar/trunk +Vcs-Mtn: www.example.org org.debian.foobar +Vcs-Hg: http://hg.debian.org/hg/foobar/pkg/foobar +Vcs-Git: git://git.debian.org/git/users/djpig/foobar.git -b master +Vcs-Cvs: :pserver:[email protected]:/cvsroot/foobar module +Vcs-Bzr: nosmart+http://bzr.debian.org/bzr/collab-maint/foobar + +Package: {$srcpkg} +Architecture: {$architecture} +Depends: $\{misc:Depends\} +Description: {$description} + This is a test package designed to exercise some feature or tag of + Lintian. It is part of the Lintian test suite and may do very odd + things. It should not be installed like a regular package. It may + be an empty package. diff --git a/t/tests/fields-uncanonical-vcs-fields/desc b/t/tests/fields-uncanonical-vcs-fields/desc new file mode 100644 index 0000000..c55751a --- /dev/null +++ b/t/tests/fields-uncanonical-vcs-fields/desc @@ -0,0 +1,6 @@ +Testname: fields-uncanonical-vcs-fields +Sequence: 6000 +Description: Test for vcs fields needing canonication +Version: 1.0 +Test-For: + vcs-field-not-canonical diff --git a/t/tests/fields-uncanonical-vcs-fields/tags b/t/tests/fields-uncanonical-vcs-fields/tags new file mode 100644 index 0000000..5631249 --- /dev/null +++ b/t/tests/fields-uncanonical-vcs-fields/tags @@ -0,0 +1,6 @@ +I: fields-uncanonical-vcs-fields source: vcs-field-not-canonical :pserver:[email protected]:/cvsroot/foobar :pserver:[email protected]:/cvs/foobar +I: fields-uncanonical-vcs-fields source: vcs-field-not-canonical git://git.debian.org/git/users/djpig/foobar.git git://anonscm.debian.org/users/djpig/foobar.git +I: fields-uncanonical-vcs-fields source: vcs-field-not-canonical http://hg.debian.org/hg/foobar/pkg/foobar http://anonscm.debian.org/hg/foobar/pkg/foobar +I: fields-uncanonical-vcs-fields source: vcs-field-not-canonical https://svn.debian.org/wsvn/foobar/trunk http://anonscm.debian.org/viewvc/foobar/trunk +I: fields-uncanonical-vcs-fields source: vcs-field-not-canonical nosmart+http://bzr.debian.org/bzr/collab-maint/foobar nosmart+http://anonscm.debian.org/bzr/collab-maint/foobar +I: fields-uncanonical-vcs-fields source: vcs-field-not-canonical svn://svn.debian.org/svn/foobar/trunk svn://anonscm.debian.org/foobar/trunk diff --git a/t/tests/fields-vcs-fields/debian/debian/control.in b/t/tests/fields-vcs-fields/debian/debian/control.in index 0aa9a61..692b807 100644 --- a/t/tests/fields-vcs-fields/debian/debian/control.in +++ b/t/tests/fields-vcs-fields/debian/debian/control.in @@ -4,13 +4,13 @@ Section: {$section} Maintainer: {$author} Standards-Version: {$standards_version} Build-Depends: debhelper (>= 9) -Vcs-Browser: https://svn.debian.org/wsvn/foobar/trunk -Vcs-Svn: svn://svn.debian.org/svn/foobar/trunk +Vcs-Browser: https://anonscm.debian.org/viewvc/foobar/trunk +Vcs-Svn: svn://anonscm.debian.org/foobar/trunk Vcs-Mtn: www.example.org org.debian.foobar -Vcs-Hg: http://hg.debian.org/hg/foobar/pkg/foobar -Vcs-Git: git://git.debian.org/git/users/djpig/foobar.git -Vcs-Cvs: :pserver:[email protected]:/cvsroot/foobar -Vcs-Bzr: nosmart+http://bzr.debian.org/bzr/collab-maint/foobar +Vcs-Hg: http://anonscm.debian.org/hg/foobar/pkg/foobar +Vcs-Git: git://anonscm.debian.org/users/djpig/foobar.git -b master +Vcs-Cvs: :pserver:[email protected]:/cvs/foobar module +Vcs-Bzr: nosmart+http://anonscm.debian.org/bzr/collab-maint/foobar Package: {$srcpkg} Architecture: {$architecture} diff --git a/t/tests/fields-vcs-fields/desc b/t/tests/fields-vcs-fields/desc index 18e3d63..171f8bd 100644 --- a/t/tests/fields-vcs-fields/desc +++ b/t/tests/fields-vcs-fields/desc @@ -5,3 +5,5 @@ Version: 1.0 Test-Against: vcs-field-uses-not-recommended-uri-format vcs-field-uses-unknown-uri-format + vcs-field-has-unexpected-spaces + vcs-field-not-canonical -- 1.7.10.4 -- To UNSUBSCRIBE, email to [email protected] with a subject of "unsubscribe". Trouble? Contact [email protected] Archive: http://lists.debian.org/[email protected]

