r48093 - /trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff

azatoth-guest at users.alioth.debian.org azatoth-guest at users.alioth.debian.org
Wed Dec 2 00:28:16 UTC 2009


Author: azatoth-guest
Date: Wed Dec  2 00:28:06 2009
New Revision: 48093

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=48093
Log:
added tests for parsing all four types, added optional flag allowUnknownFields to allow unknown fields, added matches for normally used fields whire are not specified in the policy (vcs-* and checksums-* is WTF for me) 

Modified:
    trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff

Modified: trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff?rev=48093&op=diff
==============================================================================
--- trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff (original)
+++ trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff Wed Dec  2 00:28:06 2009
@@ -1,8 +1,8 @@
 Index: libparse-debcontrol-perl/lib/Parse/DebControl.pm
 ===================================================================
---- libparse-debcontrol-perl.orig/lib/Parse/DebControl.pm	2009-12-01 23:01:10.000000000 +0100
-+++ libparse-debcontrol-perl/lib/Parse/DebControl.pm	2009-12-01 23:06:29.000000000 +0100
-@@ -18,6 +18,90 @@
+--- libparse-debcontrol-perl.orig/lib/Parse/DebControl.pm	2009-12-02 00:32:20.000000000 +0100
++++ libparse-debcontrol-perl/lib/Parse/DebControl.pm	2009-12-02 01:23:55.000000000 +0100
+@@ -18,6 +18,130 @@
  use vars qw($VERSION);
  $VERSION = '2.005';
  
@@ -79,6 +79,7 @@
 +        'architecture' => 0,
 +        'version' => 0,
 +        'distribution' => 0,
++        'description' => 1,
 +        'urgency' => 0,
 +        'maintainer' => 0,
 +        'changed-by' => 0,
@@ -88,12 +89,51 @@
 +        'files' => 1,
 +    }
 +};
++my $strict_field_match_rules = {
++    'debian/control' => qr/^\s*(
++
++    |vcs-\w+                      # not in policy
++
++    )\s*$/ix,
++    'DEBIAN/control' => qr/^\s*(
++
++    )\s*$/ix,
++    '.dsc' => qr/^\s*(
++
++    |vcs-\w+                      # not in policy
++    |checksums-\w+                # not in policy
++
++    )\s*$/ix,
++    '.changes' => qr/^\s*(
++
++    |checksums-\w+                # not in policy
++
++    )\s*$/ix,
++};
++my $strict_field_match_rules_multiline = {
++    'debian/control' => qr/^\s*(
++
++    )\s*$/ix,
++    'DEBIAN/control' => qr/^\s*(
++
++    )\s*$/ix,
++    '.dsc' => qr/^\s*(
++
++    |checksums-\w+                # not in policy
++
++    )\s*$/ix,
++    '.changes' => qr/^\s*(
++
++    |checksums-\w+                # not in policy
++
++    )\s*$/ix,
++};
 +
 +
  sub new {
  	my ($class, $debug) = @_;
  	my $this = {};
-@@ -260,12 +344,16 @@
+@@ -260,12 +384,16 @@
  		chomp $line;
  		
  
@@ -116,21 +156,25 @@
  
  		$linenum++;
  		if($line =~ /^[^\t\s]/)
-@@ -276,6 +364,13 @@
+@@ -276,6 +404,17 @@
  				my $key = $1;
  				my $value = $2;
  
 +                if( $options->{strict} ) {
 +                    if( exists $strict_field_rules->{$options->{'type'}} ) {
-+                        unless( index( lc $key, 'x-') == 0 || exists $strict_field_rules->{$options->{'type'}}->{lc $key}  ) {
-+                            throw Parse::DebControl::Error::Parse("field $lastfield for type $options->{type} is not allowed", $linenum, $line);
++                        unless(
++                            $options->{'allowUnknownFields'}
++                            || $key =~ /^X\w*?-/i
++                            || exists $strict_field_rules->{$options->{'type'}}->{lc $key}
++                            || $key =~ $strict_field_match_rules->{$options->{type} } ) {
++                            throw Parse::DebControl::Error::Parse("field '$key' for type '$options->{type}' is not allowed", $linenum, $line);
 +                        }
 +                    }
 +            }
  				if($options->{discardCase})
  				{
  					$key = lc($key);
-@@ -299,14 +394,22 @@
+@@ -299,14 +438,22 @@
                  throw Parse::DebControl::Error::Parse('invalid key/value stansa', $linenum, $line);
  			}
  
@@ -147,7 +191,7 @@
 +            }
 +            if( $options->{strict} ) {
 +                if( exists $strict_field_rules->{$options->{'type'}} ) {
-+                    unless( $strict_field_rules->{$options->{'type'}}->{lc $lastfield} == 1 ) {
++                    unless( $strict_field_rules->{$options->{'type'}}->{lc $lastfield} == 1 || $lastfield =~ $strict_field_match_rules_multiline->{$options->{'type'}} ) {
 +                        throw Parse::DebControl::Error::Parse("field $lastfield for type $options->{type} may not span multiple lines", $linenum);
 +                    }
 +                }
@@ -160,7 +204,7 @@
  			if($options->{verbMultiLine}){
  				$data->{$lastfield}.="\n$1$2";
  			}elsif($2 eq "." ){
-@@ -316,20 +419,23 @@
+@@ -316,20 +463,23 @@
  				$val =~ s/[\s\t]+$//;
  				$data->{$lastfield}.="\n$val";
  			}
@@ -197,16 +241,18 @@
  
  	}
  
-@@ -471,6 +577,20 @@
+@@ -471,6 +621,22 @@
  		it is off by default so we don't have to scrub over all the text for
  		performance reasons.
  
-+    singleBlock - only parse the first block of data and return it. This is
++    singleBlock - Only parse the first block of data and return it. This is
 +        useful when you have possible "junk" data after the metadata.
 +
 +    strict - Tries to parse obeying the strict rules for real debian control files.
 +        This will force comment stripping for debian/control (must start line) and for
 +        other files will check if a field may span multiple lines.
++
++    allowUnknownFields - In strict mode, allow unknown fields.
 +
 +    type - If the strict option is choosen, then this parameter defines what format
 +        we have. Available formats is:
@@ -221,8 +267,8 @@
 Index: libparse-debcontrol-perl/t/34strict.t
 ===================================================================
 --- /dev/null	1970-01-01 00:00:00.000000000 +0000
-+++ libparse-debcontrol-perl/t/34strict.t	2009-12-01 23:02:42.000000000 +0100
-@@ -0,0 +1,71 @@
++++ libparse-debcontrol-perl/t/34strict.t	2009-12-02 01:25:04.000000000 +0100
+@@ -0,0 +1,92 @@
 +#
 +#===============================================================================
 +#
@@ -243,7 +289,7 @@
 +use strict;
 +use warnings;
 +
-+use Test::More tests => 8;                      # last test to print
++use Test::More tests => 12;                      # last test to print
 +use Test::Exception;
 +
 +BEGIN {
@@ -262,6 +308,27 @@
 +ok($pdc = new Parse::DebControl(), "Parser object creation works fine");
 +
 +$pdc = new Parse::DebControl(1);
++
++# Parse debian/control
++lives_ok (sub {
++    $data = $pdc->parse_file( "testfiles/strict3.source", { strict => 1, type => 'debian/control', singeBlock => 1 } );
++}, "parse debian/control");
++
++# Parse DEBIAN/control
++lives_ok (sub {
++    $data = $pdc->parse_file( "testfiles/strict4.binary", { strict => 1, type => 'DEBIAN/control', singeBlock => 1 } );
++}, "parse DEBIAN/control");
++
++# Parse .changes
++lives_ok (sub {
++    $data = $pdc->parse_file( "testfiles/strict1.changes", { strict => 1, type => '.changes', singeBlock => 1 } );
++}, "parse .changes");
++
++# Parse .dsc
++lives_ok (sub {
++    $data = $pdc->parse_file( "testfiles/strict2.dsc", { strict => 1, type => '.dsc', singeBlock => 1 } );
++}, "parse .dsc");
++
 +
 +ok($data = $pdc->parse_mem("Source: foo\n#This is a comment\nPackage: bar\#another comment\n#thid comment\nPriority: required", {strict => 1, type => 'debian/control'}), "Comments parse out correctly");
 +throws_ok {
@@ -294,3 +361,85 @@
 +        {strict => 1, type => '.dsc'}
 +    )
 +} "Error not thrown when local fields is used";
+Index: libparse-debcontrol-perl/t/testfiles/strict1.changes
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ libparse-debcontrol-perl/t/testfiles/strict1.changes	2009-12-02 01:23:55.000000000 +0100
+@@ -0,0 +1,43 @@
++Format: 1.8
++Date: Sun, 29 Nov 2009 19:51:05 +0100
++Source: libparse-debcontrol-perl
++Binary: libparse-debcontrol-perl
++Architecture: source all
++Version: 2.005-3
++Distribution: UNRELEASED
++Urgency: low
++Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
++Changed-By: Carl Fürstenberg <carl at excito.com>
++Description:
++ libparse-debcontrol-perl - Easy OO parsing of Debian control-like files
++Closes: 535958
++Changes:
++ libparse-debcontrol-perl (2.005-3) UNRELEASED; urgency=low
++ .
++   [ gregor herrmann ]
++   * debian/control: Changed: Switched Vcs-Browser field to ViewSVN
++     (source stanza).
++ .
++   [ Nathan Handler ]
++   * debian/watch: Update to ignore development releases.
++ .
++   [ Carl Fürstenberg ]
++   * remove cdbs usage in favor of debhelper 7
++   * added patch for strict parsing for REAL debian control files
++     (Closes: #535958)
++   * changed to _dowarn sub to using Error instead so we actually can use
++     strict in production code
++   * Adding specific class for DEP3 patch metadata files (needs unconventional
++     parsing)
++Checksums-Sha1:
++ 270e381c3edc74b45f8849bc9bcd3530d4ad8534 1312 libparse-debcontrol-perl_2.005-3.dsc
++ 8bac7ca276601ec993b8d57dad9e2da3650c5b21 8715 libparse-debcontrol-perl_2.005-3.diff.gz
++ 5d8fa94499aefead57da8db6f80a93832ca8967b 24352 libparse-debcontrol-perl_2.005-3_all.deb
++Checksums-Sha256:
++ d5beb5e7cf627da4a454171e053054df640be9ae79d0bde6d5839ed91232e2d1 1312 libparse-debcontrol-perl_2.005-3.dsc
++ 890533ed1dbe6e77c7b416c52fa7ea48cae98d0887d7c45456057f7b26407f45 8715 libparse-debcontrol-perl_2.005-3.diff.gz
++ 168c7c287382b18be6de81cf1aaedb3f7b40bf512a71a0f46e459285b94e8ef0 24352 libparse-debcontrol-perl_2.005-3_all.deb
++Files:
++ 48ea11ea1a2cf1df823c56014bde906b 1312 perl optional libparse-debcontrol-perl_2.005-3.dsc
++ 5b1813a6d4ef35f45a53432c8fa47ddf 8715 perl optional libparse-debcontrol-perl_2.005-3.diff.gz
++ f0b93bdfe997dab7bc47437d970e644d 24352 perl optional libparse-debcontrol-perl_2.005-3_all.deb
+Index: libparse-debcontrol-perl/t/testfiles/strict3.source
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ libparse-debcontrol-perl/t/testfiles/strict3.source	2009-12-02 01:23:55.000000000 +0100
+@@ -0,0 +1,29 @@
++Source: libparse-debcontrol-perl
++Section: perl
++Priority: optional
++Build-Depends: debhelper (>= 7.0.50)
++Build-Depends-Indep: perl (>= 5.8.8-7), libio-stringy-perl, libcompress-zlib-perl, libwww-perl, libtie-ixhash-perl, libtest-pod-perl, libpod-coverage-perl
++Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
++Uploaders: Carl Fürstenberg <azatoth at gmail.com>, Gunnar Wolf <gwolf at debian.org>
++Standards-Version: 3.8.3
++Homepage: http://search.cpan.org/dist/Parse-DebControl/
++Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libparse-debcontrol-perl/
++Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libparse-debcontrol-perl/
++
++Package: libparse-debcontrol-perl
++Architecture: all
++Depends: ${perl:Depends}, ${misc:Depends}, libio-stringy-perl, libcompress-zlib-perl, libwww-perl
++Recommends: libtie-ixhash-perl, libtest-pod-perl, libpod-coverage-perl
++Description: Easy OO parsing of Debian control-like files
++ Parse::DebControl is an easy OO way to parse Debian control files and
++ other colon separated key-value pairs. It's specifically designed
++ to handle the format used in Debian control files, template files, and
++ the cache files used by dpkg.
++ .
++ For basic format information see:
++ http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-controlsyntax
++ .
++ This module does not actually do any intelligence with the file content
++ (because there are a lot of files in this format), but merely handles
++ the format. It can handle simple control files, or files hundreds of lines
++ long efficiently and easily.




More information about the Pkg-perl-cvs-commits mailing list