in reply to Form Validation and Untainting
Here's the Tie::Constrained way:
use Tie::Constrained 'detaint'; tie my $trusty, 'Tie::Constrained' , sub { &condition && &detaint; };
You can build a dispatch table - a hash of coderefs - to provide the proper \&condition for each field.
our %check; @check{@fields} = ( sub { $_[0] =~ m/^$RE{'URI'}$/; }, # . . . ); for (@fields) { my $check = $check{$_}; tie $hash{$_}, 'Tie::Constrained', sub { &$check && &detaint }; }
The detainting is done on an anonymous copy of the formerly untrusted data, so the tied variable is never tainted, and original data stays that way.
The code that does the rest of the work can be written as if it never heard of taint mode.
After Compline,
Zaxo
|
---|