Skip Menu |
 

This queue is for tickets about the CGI-ValidOp CPAN distribution.

Report information
The Basics
Id: 60127
Status: new
Priority: 0/
Queue: CGI-ValidOp

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.56
Fixed in: (no value)

Attachments
0001-Given-a-true-but-invalid-ISO-date-the-check-would-wa.patch



Subject: date::iso can throw warnings in certain conditions (with patch)
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1281063913-3536-41"
Content-Length: 0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 983
Download (untitled) / with headers
text/plain 983b
date::iso can throw warnings under certain conditions, like when its given a true but obviously non-date value and options like past and present are there. $ perl -Twle 'use CGI::ValidOp; use CGI::ValidOp::Test; check_check( "date::iso(past,present)", "foobar", undef, 0 );' ok 1 ok 2 ok 3 - testing: foobar = with date::iso(past,present) Use of uninitialized value $value[0] in numeric gt (>) at /usr/local/perl/5.10.1/lib/site_perl/5.10.1/CGI/ValidOp/Check/date.pm line 98. ok 4 - -e : 1 # Tests were run but no plan was declared and done_testing() was not seen. Turns out the problem is my($y,$m,$d) = check_iso_format($value) or return; and that check_iso_format() will sometimes return an explicit undef. The above is actually: ( my($y,$m,$d = check_iso_format($value) ) or return; so when check_iso_format() returns undef the LHS of that condition is a list of size one which is true. The solution is to use just "return" which will do the right thing. Patch attached.
Subject: 0001-Given-a-true-but-invalid-ISO-date-the-check-would-wa.patch
MIME-Version: 1.0
Content-Type: text/x-diff; name="0001-Given-a-true-but-invalid-ISO-date-the-check-would-wa.patch"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="0001-Given-a-true-but-invalid-ISO-date-the-check-would-wa.patch"
Content-Transfer-Encoding: binary
Content-Length: 2164
From 0bd54274bc8e2a3cee7fccfece7362e30a926051 Mon Sep 17 00:00:00 2001 From: Michael G. Schwern <schwern@pobox.com> Date: Thu, 5 Aug 2010 19:57:34 -0700 Subject: [PATCH] Given a true but invalid ISO date, the check would warn. Turns out the problem is my($y,$m,$d) = check_iso_format($value) or return; and that check_iso_format() will sometimes return an explicit undef. The above is actually: ( my($y,$m,$d = check_iso_format($value) ) or return; so when check_iso_format() returns undef the LHS of that condition is a list of size one which is true. The solution is to use just "return" which will do the right thing. --- lib/CGI/ValidOp/Check/date.pm | 4 ++-- t/16check_date.t | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/CGI/ValidOp/Check/date.pm b/lib/CGI/ValidOp/Check/date.pm index 3574ea7..3ac0869 100644 --- a/lib/CGI/ValidOp/Check/date.pm +++ b/lib/CGI/ValidOp/Check/date.pm @@ -120,7 +120,7 @@ sub check_iso_format { my( $y, $m, $d ) = $date =~ qr#^(\d{1,4})-(\d{1,2})-(\d{1,2})$# - or return undef; + or return; return ($y, $m, $d); } @@ -133,7 +133,7 @@ sub check_american_format { my( $m, $d, $y ) = $date =~ qr#^(\d{1,2})(?:-|/)(\d{1,2})(?:-|/)(\d{4})$# - or return undef; + or return; return ($y, $m, $d); } diff --git a/t/16check_date.t b/t/16check_date.t index 932f980..83d14fa 100755 --- a/t/16check_date.t +++ b/t/16check_date.t @@ -6,7 +6,8 @@ use lib qw/ t lib /; use CGI::ValidOp::Test; -use Test::More tests => 607; +use Test::NoWarnings; +use Test::More tests => 612; use vars qw/ $one $errmsg /; use Data::Dumper; use Test::Taint; @@ -130,6 +131,7 @@ BEGIN { use_ok( 'CGI::ValidOp::Param' )} # iso my $errmsg = 'William Blake must include year, month, and date as YYYY-MM-DD'; check_check( 'date::iso', undef, undef, 0 ); + check_check( 'date::iso(past,present)', 'foobar', undef, 0 ); check_check( 'date::iso', 10, undef, 0, $errmsg ); check_check( 'date::iso', '2004', undef, 0, $errmsg ); check_check( 'date::iso', '2004-10', undef, 0, $errmsg ); -- 1.7.2


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.