File: twodigit.t

package info (click to toggle)
libcgi-untaint-perl 1.26-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 112 kB
  • ctags: 21
  • sloc: perl: 302; makefile: 6
file content (28 lines) | stat: -rw-r--r-- 616 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl -w

use strict;
use Test::More;
use CGI;
use CGI::Untaint;

plan tests => 5;

package CGI::Untaint::twodigit;

use base 'CGI::Untaint::integer';

sub _untaint_re { return qr/^\s*([0-9]{2})\s*$/ }

package main;

my $q = CGI->new( { foo => 12, bar => 0, baz => "" } );
my $h = CGI::Untaint->new($q->Vars);

is $h->extract(-as_twodigit => "foo"), 12, "12 extracts";

is $h->extract(-as_twodigit => "bar"), undef, "0 doesn't";
like $h->error, qr/does not untaint/, "With error";

is $h->extract(-as_twodigit => "baz"), undef, "empty string doesn't";
like $h->error, qr/does not untaint/, "With error";