in reply to Re: What's your favourite method of untainting?
in thread What's your favourite method of untainting?

Do you write code like that?
my $foo = $bar =~ m!(acceptable_value|allowed_value)! ? $1 : die 'Invalid value of tainted $bar: ' . $bar;
(though I'm not sure why you have $bar twice in the error message...)

Replies are listed 'Best First'.
Re^3: What's your favourite method of untainting?
by kcott (Archbishop) on Nov 10, 2023 at 08:37 UTC
    ... : die 'Invalid value of tainted $bar: ' . $bar;
    (though I'm not sure why you have $bar twice in the error message...)

    First $bar is within single quotes, so not interpolated; second $bar is interpolated. die message will look like this:

    Invalid value of tainted $bar: tainted_bar_value ...

    — Ken

Re^3: What's your favourite method of untainting?
by Bod (Parson) on Nov 12, 2023 at 00:26 UTC
    Do you write code like that?

    Yes...

    It is clear exactly what it does and it's easy to maintain even by a non-Perl expert (perhaps that should be a Perl non-expert!)