>>>>> "JJL" == John J Lee <[EMAIL PROTECTED]> writes:

  JJL> On 2 Aug 2002, Uri Guttman wrote:
  JJL> [...]
  >> i also found an odd problem with date parsing in HTTP/Date.pm
  JJL> [...code from lwp snipped]
  >> if $mon is not a 3 char month, but it is a string, it will be
  >> numerically compared to 1 and 12 and generate a warning. i suggest
  JJL> [...]

  JJL> Could you post a test case, please?  Doesn't have to be an
  JJL> executable one, just a date string that triggers the problem?

well, i lost the web address that triggered this. i fixed up the crawler
so it will log that in the future.

the hash only checks the 3 char month names but it allows 1-3 char
months in the ctime format. since a short month is not in the hash the
month string is then numerically compared to 1 < 12 and that warns.

    # Translate month name to number
    $mon = $MoY{$mon} ||
           $MoY{"\u\L$mon"} ||
           ($mon >= 1 && $mon <= 12 && int($mon)) ||
           return;

i don't know what the int($mon) is doing there. it will generate the
same warning as the as the >= ops do. so it isn't a useful check. a
digit check fixes this:

        ($mon !~ /\D/ && $mon >= 1 && $mon <= 12)

#!/usr/local/bin/perl -w

use strict ;

use HTTP::Date ;


while( <DATA> ) {

        chomp;
        my $date = HTTP::Date::parse_date( $_ ) || 'BAD' ;
        print "DATE: $_ = $date\n" ;
}

__END__
Fri Aug  9 08:35:19 PDT 2002
Fri August  9 08:35:19 PDT 2002
Fri June  9 08:35:19 PDT 2002
Fri July  9 08:35:19 PDT 2002
Fri Ju  9 08:35:19 PDT 2002


this is broken code i think. the {1,3} should be just a {3} as it is
in the ls -l regex just below this one.

    # Try the ctime and asctime format
    (($mon, $day, $hr, $min, $sec, $tz, $yr) =
        /^
         (\w{1,3})             # month
            \s+

changing that to {3} removes the numeric warning.

it will then just return undef for a bad date with a 2 char month.


so i would put both fixes in there. change the month length count to {3}
and change the month numeric range check to:

        ($mon !~ /\D/ && $mon >= 1 && $mon <= 12)


thanx,

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Reply via email to