Package: libparse-debianchangelog-perl
Version: 1.1-1
Tags: patch

Parse::DebianChangelog calls Date::Parse's str2time but misinterprets
the return value.  str2time's error value is undef, but the calling
code tests for false, which includes zero.  This causes the parser to
fail to work with timestamp 0, even though it is a valid timestamp.

Here is a short test program:


#! /usr/bin/perl -w

# test Parse::DebianChangelog's handling of the epoch
# by Stephen Gildea, August 2007

use Parse::DebianChangelog;

my $changelog_entry =
'test-package (1.0) unstable; urgency=low

  * Verify that parsechangelog knows the epoch is a valid date.
        
 -- Terry Hacker <[EMAIL PROTECTED]>  Thu, 01 Jan 1970 00:00:00 +0000';

my $changes = Parse::DebianChangelog->init({ instring => $changelog_entry });
if ($changes->get_parse_errors) {
    exit 1;
}

print "Parse of changelog succeeded.\n";


----------------------------------

And here is a patch to fix the bug:


--- libparse-debianchangelog-perl-1.1/lib/Parse/DebianChangelog.pm      
2007-07-15 22:11:53 -0400
+++ lib/Parse/DebianChangelog.pm        2007-08-28 23:41:17 -0400
@@ -403,12 +403,14 @@ sub parse {
            }
            $entry->{'Trailer'} = $_;
            $entry->{'Maintainer'} = "$1 <$2>" unless $entry->{'Maintainer'};
-           unless($entry->{'Date'} && $entry->{'Timestamp'}) {
+           unless($entry->{'Date'} && defined $entry->{'Timestamp'}) {
                $entry->{'Date'} = "$4";
-               $entry->{'Timestamp'} = str2time($4)
-                   or $self->_do_parse_error( $file, $NR,
-                                              __g( "couldn't parse date %s",
-                                                   "$4" ) );
+               $entry->{'Timestamp'} = str2time($4);
+               unless (defined $entry->{'Timestamp'}) {
+                   $self->_do_parse_error( $file, $NR,
+                                           __g( "couldn't parse date %s",
+                                                "$4" ) );
+               }
            }
            $expect = 'next heading or eof';
        } elsif (m/^ \-\-/) {
@@ -962,7 +964,7 @@ sub html {
     my $last_year;
     foreach my $entry (@$data) {
        my $year = $last_year; # try to deal gracefully with unparsable dates
-       if ($entry->{Timestamp}) {
+       if (defined $entry->{Timestamp}) {
            $year = (gmtime($entry->{Timestamp}))[5] + 1900;
            $last_year = $year;
        }
@@ -992,7 +994,7 @@ sub html {
     $last_year = undef;
     foreach my $entry (@$data) {
        my $year = $last_year; # try to deal gracefully with unparsable dates
-       if ($entry->{Timestamp}) {
+       if (defined $entry->{Timestamp}) {
            $year = (gmtime($entry->{Timestamp}))[5] + 1900;
        }
        $year ||= (($entry->{Date} =~ /\s(\d{4})\s/) ? $1 : (gmtime)[5] + 1900);


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to