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

azatoth-guest at users.alioth.debian.org azatoth-guest at users.alioth.debian.org
Tue Dec 1 00:32:50 UTC 2009


Author: azatoth-guest
Date: Tue Dec  1 00:32:45 2009
New Revision: 48022

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=48022
Log:
rewrite some strict rules, only look as field existance and single line only fields, added some more tests for strictness

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=48022&op=diff
==============================================================================
--- trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff (original)
+++ trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff Tue Dec  1 00:32:45 2009
@@ -1,8 +1,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 00:59:02.000000000 +0100
-@@ -0,0 +1,47 @@
++++ libparse-debcontrol-perl/t/34strict.t	2009-12-01 01:31:19.000000000 +0100
+@@ -0,0 +1,71 @@
 +#
 +#===============================================================================
 +#
@@ -23,7 +23,7 @@
 +use strict;
 +use warnings;
 +
-+use Test::More tests => 4;                      # last test to print
++use Test::More tests => 8;                      # last test to print
 +use Test::Exception;
 +
 +BEGIN {
@@ -50,10 +50,34 @@
 +        {strict => 1, type => 'DEBIAN/control'}
 +    )
 +} 'Parse::DebControl::Error::Parse', "Error thrown";
++throws_ok {
++    $pdc->parse_mem(
++        "Source: foo\nPackage: bar\nExtra: candy for me",
++        {strict => 1, type => 'debian/control'}
++    )
++} 'Parse::DebControl::Error::Parse', "Error thrown for the extra field";
++lives_ok {
++    $pdc->parse_mem(
++        "Format: 1.8\nSource: bar\n\nExtra: candy for me",
++        {strict => 1, type => '.dsc', singleBlock => 1}
++    )
++} "Error not thrown when ignoring junk";
++throws_ok {
++    $pdc->parse_mem(
++        "Source: foo\nPackage: bar\n\nExtra: candy for me",
++        {strict => 1, type => 'debian/control'}
++    )
++} 'Parse::DebControl::Error::Parse', "Error thrown for the extra block";
++lives_ok {
++    $pdc->parse_mem(
++        "Format: 1.8\nSource: bar\nX-Extra: candy for me",
++        {strict => 1, type => '.dsc'}
++    )
++} "Error not thrown when local fields is used";
 Index: libparse-debcontrol-perl/lib/Parse/DebControl/Error.pm
 ===================================================================
 --- /dev/null	1970-01-01 00:00:00.000000000 +0000
-+++ libparse-debcontrol-perl/lib/Parse/DebControl/Error.pm	2009-12-01 00:59:02.000000000 +0100
++++ libparse-debcontrol-perl/lib/Parse/DebControl/Error.pm	2009-12-01 01:02:57.000000000 +0100
 @@ -0,0 +1,75 @@
 +use strict;
 +use warnings;
@@ -133,8 +157,8 @@
 Index: libparse-debcontrol-perl/lib/Parse/DebControl/Patch.pm
 ===================================================================
 --- /dev/null	1970-01-01 00:00:00.000000000 +0000
-+++ libparse-debcontrol-perl/lib/Parse/DebControl/Patch.pm	2009-12-01 00:59:02.000000000 +0100
-@@ -0,0 +1,156 @@
++++ libparse-debcontrol-perl/lib/Parse/DebControl/Patch.pm	2009-12-01 01:02:57.000000000 +0100
+@@ -0,0 +1,155 @@
 +package Parse::DebControl::Patch;
 +use strict;
 +use warnings;
@@ -148,7 +172,6 @@
 +our $Forwarded_No = 2,
 +our $Forwarded_NotNeeded = 3,
 +
-+our @EXPORT = qw($Forwared_Yes $Forwared_No $Forwared_NotNeeded);
 +our @EXPORT_OK = qw($Forwared_Yes $Forwared_No $Forwared_NotNeeded);
 +
 +our $VERSION = '0.1';
@@ -294,7 +317,7 @@
 Index: libparse-debcontrol-perl/t/35patch.t
 ===================================================================
 --- /dev/null	1970-01-01 00:00:00.000000000 +0000
-+++ libparse-debcontrol-perl/t/35patch.t	2009-12-01 00:59:02.000000000 +0100
++++ libparse-debcontrol-perl/t/35patch.t	2009-12-01 01:02:57.000000000 +0100
 @@ -0,0 +1,76 @@
 +#
 +#===============================================================================
@@ -375,7 +398,7 @@
 Index: libparse-debcontrol-perl/t/testfiles/patch1.diff
 ===================================================================
 --- /dev/null	1970-01-01 00:00:00.000000000 +0000
-+++ libparse-debcontrol-perl/t/testfiles/patch1.diff	2009-12-01 00:59:02.000000000 +0100
++++ libparse-debcontrol-perl/t/testfiles/patch1.diff	2009-12-01 01:02:57.000000000 +0100
 @@ -0,0 +1,27 @@
 +From: Ulrich Drepper <drepper at redhat.com>
 +Subject: Fix regex problems with some multi-bytes characters
@@ -406,9 +429,9 @@
 +
 Index: libparse-debcontrol-perl/lib/Parse/DebControl.pm
 ===================================================================
---- libparse-debcontrol-perl.orig/lib/Parse/DebControl.pm	2009-12-01 00:59:12.000000000 +0100
-+++ libparse-debcontrol-perl/lib/Parse/DebControl.pm	2009-12-01 00:59:16.000000000 +0100
-@@ -13,10 +13,111 @@
+--- libparse-debcontrol-perl.orig/lib/Parse/DebControl.pm	2009-12-01 01:02:07.000000000 +0100
++++ libparse-debcontrol-perl/lib/Parse/DebControl.pm	2009-12-01 01:31:33.000000000 +0100
+@@ -13,10 +13,94 @@
  use IO::Scalar;
  use Compress::Zlib;
  use LWP::UserAgent;
@@ -417,110 +440,93 @@
  use vars qw($VERSION);
  $VERSION = '2.005';
  
-+# in strict mode following fields may not have linebreaks
-+my $strict_single_line_fields = {
++# in strict mode, following specifies what fields are OK, and
++# if they might have multiline data
++my $strict_field_rules = {
 +    'debian/control' => {
-+        'source' => 1,
-+        'maintainer' => 1,
-+        'section' => 1,
-+        'priority' => 1,
-+        'package' => 1,
-+        'architecture' => 1,
-+        'essential' => 1,
-+        'standards-version' => 1,
-+        'homepage' => 1,
++        'source' => 0,
++        'maintainer' => 0,
++        'uploaders' => 1,
++        'section' => 0,
++        'priority' => 0,
++        'build-depends' => 1,
++        'build-depends-indep' => 1,
++        'build-conflicts' => 1,
++        'build-conflicts-indep' => 1,
++        'depends' => 1,
++        'pre-depends' => 1,
++        'recommends' => 1,
++        'suggests' => 1,
++        'enhances' => 1,
++        'breaks' => 1,
++        'conflicts' => 1,
++        'description' => 1,
++        'package' => 0,
++        'architecture' => 0,
++        'essential' => 0,
++        'standards-version' => 0,
++        'homepage' => 0,
 +    },
 +    'DEBIAN/control' => {
-+        'source' => 1,
-+        'maintainer' => 1,
-+        'changed-by' => 1,
-+        'section' => 1,
-+        'priority' => 1,
-+        'package' => 1,
-+        'architecture' => 1,
-+        'essential' => 1,
-+        'version' => 1,
-+        'installed-size' => 1,
-+        'homepage' => 1,
++        'source' => 0,
++        'maintainer' => 0,
++        'changed-by' => 0,
++        'section' => 0,
++        'priority' => 0,
++        'package' => 0,
++        'architecture' => 0,
++        'essential' => 0,
++        'version' => 0,
++        'installed-size' => 0,
++        'homepage' => 0,
++        'depends' => 1,
++        'pre-depends' => 1,
++        'recommends' => 1,
++        'suggests' => 1,
++        'enhances' => 1,
++        'breaks' => 1,
++        'conflicts' => 1,
++        'description' => 1,
++        'description' => 1,
 +    },
 +    '.dsc'  => {
-+        'format' => 1,
-+        'date' => 1,
-+        'source' => 1,
-+        'version' => 1,
-+        'maintainer' => 1,
-+        'architecture' => 1,
-+        'standards-version' => 1,
-+        'homepage' => 1,
++        'format' => 0,
++        'date' => 0,
++        'source' => 0,
++        'version' => 0,
++        'maintainer' => 0,
++        'architecture' => 0,
++        'standards-version' => 0,
++        'homepage' => 0,
++        'uploaders' => 1,
++        'binary' => 1,
++        'build-depends' => 1,
++        'build-depends-indep' => 1,
++        'build-conflicts' => 1,
++        'build-conflicts-indep' => 1,
++        'files' => 1,
 +    },
 +    '.changes' => {
-+        'format' => 1,
-+        'date' => 1,
-+        'source' => 1,
-+        'architecture' => 1,
-+        'version' => 1,
-+        'distribution' => 1,
-+        'urgency' => 1,
-+        'maintainer' => 1,
-+        'changed-by' => 1,
-+        'closes' => 1,
-+    }
-+};
-+
-+# TODO fill in more rules
-+my $strict_rules = {
-+    'debian/control' => {
-+        'source' => qr'^\s*\w+\s*$'o,
-+        'maintainer' => qr''o,
-+        'section' => qr''o,
-+        'priority' => qr''o,
-+        'package' => qr''o,
-+        'architecture' => qr''o,
-+        'essential' => qr''o,
-+        'standards-version' => qr''o,
-+        'homepage' => qr''o,
-+    },
-+    'DEBIAN/control' => {
-+        'source' => qr'^\s*\w+\s*(?:\(.*\))?$'o,
-+        'maintainer' => qr''o,
-+        'changed-by' => qr''o,
-+        'section' => qr''o,
-+        'priority' => qr''o,
-+        'package' => qr''o,
-+        'architecture' => qr''o,
-+        'essential' => qr''o,
-+        'version' => qr''o,
-+        'installed-size' => qr''o,
-+        'homepage' => qr''o,
-+    },
-+    '.dsc'  => {
-+        'source' => qr'^\s*\w+\s*$'o,
-+        'format' => qr''o,
-+        'date' => qr''o,
-+        'version' => qr''o,
-+        'maintainer' => qr''o,
-+        'architecture' => qr''o,
-+        'standards-version' => qr''o,
-+        'homepage' => qr''o,
-+    },
-+    '.changes' => {
-+        'source' => qr'^\s*\w+\s*(?:\(.*\))?$'o,
-+        'format' => qr''o,
-+        'date' => qr''o,
-+        'architecture' => qr''o,
-+        'version' => qr''o,
-+        'distribution' => qr''o,
-+        'urgency' => qr''o,
-+        'maintainer' => qr''o,
-+        'changed-by' => qr''o,
-+        'closes' => qr''o,
++        'format' => 0,
++        'date' => 0,
++        'source' => 0,
++        'architecture' => 0,
++        'version' => 0,
++        'distribution' => 0,
++        'urgency' => 0,
++        'maintainer' => 0,
++        'changed-by' => 0,
++        'closes' => 0,
++        'binary' => 1,
++        'changes' => 1,
++        'files' => 1,
 +    }
 +};
 +
  sub new {
  	my ($class, $debug) = @_;
  	my $this = {};
-@@ -33,15 +134,13 @@
+@@ -33,15 +117,13 @@
  	my ($this, $filename, $options) = @_;
  	unless($filename)
  	{
@@ -538,7 +544,7 @@
  	}
  	
  	return $this->_parseDataHandle($fh, $options);
-@@ -52,16 +151,14 @@
+@@ -52,16 +134,14 @@
  
  	unless($data)
  	{
@@ -557,7 +563,7 @@
  	}
  
  	return $this->_parseDataHandle($IOS, $options);
-@@ -73,8 +170,7 @@
+@@ -73,8 +153,7 @@
  
  	unless($url)
  	{
@@ -567,7 +573,7 @@
  	}
  
  	my $ua = LWP::UserAgent->new;
-@@ -83,8 +179,7 @@
+@@ -83,8 +162,7 @@
  
  	unless($request)
  	{
@@ -577,7 +583,7 @@
  	}
  
  	my $response = $ua->request($request);
-@@ -92,8 +187,7 @@
+@@ -92,8 +170,7 @@
  	if ($response->is_success) {
  		return $this->parse_mem($response->content(), $options);
  	} else {
@@ -587,7 +593,7 @@
  	}
  }
  
-@@ -102,22 +196,19 @@
+@@ -102,22 +179,19 @@
  
  	unless($filenameorhandle)
  	{
@@ -613,7 +619,7 @@
  	}
  
  	my $string = $this->write_mem($dataorarrayref, $options);
-@@ -134,8 +225,7 @@
+@@ -134,8 +208,7 @@
  
  	unless($dataorarrayref)
  	{
@@ -623,7 +629,7 @@
  	}
  
  	my $arrayref = $this->_makeArrayref($dataorarrayref);
-@@ -165,8 +255,7 @@
+@@ -165,8 +238,7 @@
  	{
  		unless($filenameorhandle->opened())
  		{
@@ -633,7 +639,7 @@
  		}
  
  		return $filenameorhandle;
-@@ -180,8 +269,7 @@
+@@ -180,8 +252,7 @@
  
  		unless(open $handle,"$openmode$filenameorhandle")
  		{
@@ -643,7 +649,7 @@
  		}
  
  		return $handle;
-@@ -248,8 +336,7 @@
+@@ -248,8 +319,7 @@
  
  	unless($handle)
  	{
@@ -653,7 +659,7 @@
  	}
  
  	if($options->{tryGzip})
-@@ -273,12 +360,16 @@
+@@ -273,12 +343,16 @@
  		chomp $line;
  		
  
@@ -676,7 +682,21 @@
  
  		$linenum++;
  		if($line =~ /^[^\t\s]/)
-@@ -309,19 +400,27 @@
+@@ -289,6 +363,13 @@
+ 				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);
++                        }
++                    }
++            }
+ 				if($options->{discardCase})
+ 				{
+ 					$key = lc($key);
+@@ -309,19 +390,25 @@
  
  				$lastfield = $key;
  			}else{
@@ -696,12 +716,10 @@
 +                throw Parse::DebControl::Error::Parse('indented entry without previous line', $linenum, $line);
 +            }
 +            if( $options->{strict} ) {
-+                if(
-+                    exists $strict_single_line_fields->{$options->{type}}
-+                    && exists $strict_single_line_fields->{$options->{type}}->{lc $lastfield}
-+                    && $strict_single_line_fields->{$options->{type}}->{lc $lastfield} == 1
-+                ) {
-+                    throw Parse::DebControl::Error::Parse("field $lastfield for type $options->{type} may not span multiple lines", $linenum);
++                if( exists $strict_field_rules->{$options->{'type'}} ) {
++                    unless( $strict_field_rules->{$options->{'type'}}->{lc $lastfield} == 1 ) {
++                        throw Parse::DebControl::Error::Parse("field $lastfield for type $options->{type} may not span multiple lines", $linenum);
++                    }
 +                }
 +            }
  
@@ -713,7 +731,7 @@
  			if($options->{verbMultiLine}){
  				$data->{$lastfield}.="\n$1$2";
  			}elsif($2 eq "." ){
-@@ -332,20 +431,29 @@
+@@ -332,20 +419,23 @@
  				$data->{$lastfield}.="\n$val";
  			}
  
@@ -736,17 +754,11 @@
 +                && ($data->{$lastfield} =~ /\n/o)) {
 +                $data->{$lastfield} .= "\n";
 +            }
-+            if( $options->{strict} ) {
-+                if(
-+                    exists $strict_rules->{$options->{type}}
-+                    && exists $strict_rules->{$options->{type}}->{lc $lastfield}
-+                    && $data->{$lastfield} !~ $strict_rules->{$options->{type}}->{lc $lastfield}
-+                ) {
-+                    throw Parse::DebControl::Error::Parse("field $lastfield for type $options->{type} doesn't match rule", $linenum);
++
++            if(keys %$data > 0){
++                if( $options->{singleBlock} ) {
++                    return $data;
 +                }
-+
-+            }
-+            if(keys %$data > 0){
 +                push @$structs, $data;
 +            }
 +            $data = $this->_getReadyHash($options);
@@ -757,7 +769,7 @@
  
  	}
  
-@@ -379,8 +487,7 @@
+@@ -379,8 +469,7 @@
  		eval("use Tie::IxHash");
  		if($@)
  		{
@@ -767,7 +779,7 @@
  		}
  		tie(%$data, "Tie::IxHash");
  		return $data;
-@@ -389,19 +496,6 @@
+@@ -389,19 +478,6 @@
  	return {};
  }
  
@@ -787,10 +799,13 @@
  1;
  
  __END__
-@@ -501,6 +595,17 @@
+@@ -501,6 +577,20 @@
  		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
++        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.




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