diff options
author | Andy Lester <andy@petdance.com> | 2004-08-26 18:44:47 -0500 |
---|---|---|
committer | Dave Mitchell <davem@fdisolutions.com> | 2004-09-01 22:45:07 +0000 |
commit | 23634c1038ac02e06ed94c94fa7451ed7bca7315 (patch) | |
tree | 0c66f1f3f23780d1328573519de5bbf2e8c2d6d2 /t | |
parent | 45b25de691b683a193abf9d0c8a3bcbeaedd693c (diff) | |
download | perl-23634c1038ac02e06ed94c94fa7451ed7bca7315.tar.gz |
PATCH: Taintedness and ternary conditional
Message-Id: <20040827044447.GA5268@petdance.com>
add tests and documentation to the effect that ($tainted ? $a : $b)
doesn't necessarily return a tainted value. Also tidy the markup in
perldoc.pod
p4raw-id: //depot/perl@23253
Diffstat (limited to 't')
-rwxr-xr-x | t/op/taint.t | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/t/op/taint.t b/t/op/taint.t index 6c35e86bf4..2204632b45 100755 --- a/t/op/taint.t +++ b/t/op/taint.t @@ -16,6 +16,7 @@ use strict; use Config; use File::Spec::Functions; +my $total_tests = 236; my $test = 177; sub ok ($;$) { my($ok, $name) = @_; @@ -124,7 +125,7 @@ my $echo = "$Invoke_Perl $ECHO"; my $TEST = catfile(curdir(), 'TEST'); -print "1..223\n"; +print "1..$total_tests\n"; # First, let's make sure that Perl is checking the dangerous # environment variables. Maybe they aren't set yet, so we'll @@ -1045,3 +1046,39 @@ else eval '$^O = $^X'; test 223, $@ =~ /Insecure dependency in/; } + +EFFECTIVELY_CONSTANTS: { + my $tainted_number = 12 + $TAINT0; + test 224, tainted( $tainted_number ); + + # Even though it's always 0, it's still tainted + my $tainted_product = $tainted_number * 0; + test 225, tainted( $tainted_product ); + test 226, $tainted_product == 0; +} + +TERNARY_CONDITIONALS: { + my $tainted_true = $TAINT . "blah blah blah"; + my $tainted_false = $TAINT0; + test 227, tainted( $tainted_true ); + test 228, tainted( $tainted_false ); + + my $result = $tainted_true ? "True" : "False"; + test 229, $result eq "True"; + test 230, !tainted( $result ); + + $result = $tainted_false ? "True" : "False"; + test 231, $result eq "False"; + test 232, !tainted( $result ); + + my $untainted_whatever = "The Fabulous Johnny Cash"; + my $tainted_whatever = "Soft Cell" . $TAINT; + + $result = $tainted_true ? $tainted_whatever : $untainted_whatever; + test 233, $result eq "Soft Cell"; + test 234, tainted( $result ); + + $result = $tainted_false ? $tainted_whatever : $untainted_whatever; + test 235, $result eq "The Fabulous Johnny Cash"; + test 236, !tainted( $result ); +} |