1#!/usr/bin/perl -Tw 2 3use strict; 4 5use Params::Validate qw(validate validate_pos); 6use Test::More; 7 8eval "use Test::Taint 0.02"; 9if ($@) 10{ 11 plan skip_all => 'These tests require Test::Taint 0.02+ to run'; 12} 13else 14{ 15 plan tests => 9; 16} 17 18taint_checking_ok( 'These tests are meaningless unless we are in taint mode.' ); 19 20{ 21 my $value = 7; 22 taint($value); 23 24 tainted_ok( $value, 'make sure $value is tainted' ); 25 26 my @p = ( value => $value ); 27 my %p = validate( @p, { value => { regex => qr/^\d+$/, 28 untaint => 1, 29 }, 30 }, 31 ); 32 33 untainted_ok( $p{value}, 'value is untainted after validation' ); 34} 35 36{ 37 my $value = 'foo'; 38 39 taint($value); 40 41 tainted_ok( $value, 'make sure $value is tainted' ); 42 43 my @p = ( $value ); 44 my ($new_value) = validate_pos( @p, { regex => qr/foo/, 45 untaint => 1, 46 }, 47 ); 48 49 untainted_ok( $new_value, 'value is untainted after validation' ); 50} 51 52{ 53 my $value = 7; 54 taint($value); 55 56 tainted_ok( $value, 'make sure $value is tainted' ); 57 58 my @p = ( value => $value ); 59 my %p = validate( @p, { value => { regex => qr/^\d+$/, 60 }, 61 }, 62 ); 63 64 tainted_ok( $p{value}, 'value is still tainted after validation' ); 65} 66 67{ 68 my $value = 'foo'; 69 70 taint($value); 71 72 tainted_ok( $value, 'make sure $value is tainted' ); 73 74 my @p = ( $value ); 75 my ($new_value) = validate_pos( @p, { regex => qr/foo/, 76 }, 77 ); 78 79 tainted_ok( $new_value, 'value is still tainted after validation' ); 80} 81