line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::date; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '1.00'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
16821
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'CGI::Untaint::printable'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4954
|
|
7
|
1
|
|
|
1
|
|
3566
|
use Date::Manip; |
|
1
|
|
|
|
|
190145
|
|
|
1
|
|
|
|
|
268
|
|
8
|
1
|
|
|
1
|
|
1199
|
use Date::Simple; |
|
1
|
|
|
|
|
6806
|
|
|
1
|
|
|
|
|
214
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub is_valid { |
11
|
4
|
|
|
4
|
1
|
11882
|
my $self = shift; |
12
|
4
|
|
|
4
|
|
34
|
local $SIG{__WARN__} = sub {}; |
|
4
|
|
|
|
|
14
|
|
13
|
4
|
|
|
0
|
|
73
|
local *Date::Manip::Date_TimeZone = sub { 'GMT' }; |
|
0
|
|
|
|
|
0
|
|
14
|
4
|
|
|
|
|
21
|
Date_Init(sprintf 'DateFormat=%s' => $self->date_format); |
15
|
4
|
50
|
|
|
|
445
|
my $date = ParseDate($self->value) or return; |
16
|
4
|
|
|
|
|
93054
|
my @date = unpack "A4A2A2", $date; |
17
|
4
|
50
|
|
|
|
15
|
my $ds = eval { Date::Simple->new(@date) } or return; |
|
4
|
|
|
|
|
32
|
|
18
|
4
|
|
|
|
|
463
|
$self->value($ds); |
19
|
4
|
|
|
|
|
81
|
return $ds; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
1
|
36
|
sub date_format { 'UK' } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
CGI::Untaint::date - validate a date |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use CGI::Untaint; |
31
|
|
|
|
|
|
|
my $handler = CGI::Untaint->new($q->Vars); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $date = $handler->extract(-as_date => 'date'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 is_valid |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This Input Handler verifies that it is dealing with a reasonable |
40
|
|
|
|
|
|
|
date. Reasonably means anything that Date::Manip thinks is |
41
|
|
|
|
|
|
|
sensible, so you could use any of (for example): |
42
|
|
|
|
|
|
|
"December 12, 2001" |
43
|
|
|
|
|
|
|
"12th December, 2001" |
44
|
|
|
|
|
|
|
"2001-12-12" |
45
|
|
|
|
|
|
|
"next Tuesday" |
46
|
|
|
|
|
|
|
"third Wednesday in March" |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
See L for much more information on what date formats are |
49
|
|
|
|
|
|
|
acceptable. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The resulting date will be a Date::Simple object. |
52
|
|
|
|
|
|
|
L for more information on this. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 date_format |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
By default ambiguous dates of the format 08/09/2001 will be treated as |
57
|
|
|
|
|
|
|
UK style (i.e. 8th September rather than 9th August) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
If you want to change this, subclass it and override date_format() |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 WARNING |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Date::Manip does not play nicely with taint mode. In order to work |
64
|
|
|
|
|
|
|
around this we locally clobber Date::Manip's 'timezone' code. As we're |
65
|
|
|
|
|
|
|
only interested in dates rather than times, this shouldn't be much of |
66
|
|
|
|
|
|
|
an issue. If it is, then please let me know! |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SEE ALSO |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
L. L. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 AUTHOR |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Tony Bowden |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 BUGS and QUERIES |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Please direct all correspondence regarding this module to: |
79
|
|
|
|
|
|
|
bug-CGI-Untaint-date@rt.cpan.org |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT and LICENSE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Copyright (C) 2001-2005 Tony Bowden. All rights reserved. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify |
86
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |