Blame t/taint/basic.t

Packit e6c7a3
#!/usr/bin/perl -T
Packit e6c7a3
#
Packit e6c7a3
# Check that Term::ANSIColor untaints generated constants.
Packit e6c7a3
#
Packit e6c7a3
# It's possible that the name of the constant function that we're calling
Packit e6c7a3
# could be tained (such as by loading the name of the constant function from
Packit e6c7a3
# an environment variable).  Term::ANSIColor does the work to untaint it; be
Packit e6c7a3
# sure that the taint flag is properly cleared.
Packit e6c7a3
#
Packit e6c7a3
# Copyright 2012 Russ Allbery <rra@cpan.org>
Packit e6c7a3
#
Packit e6c7a3
# This program is free software; you may redistribute it and/or modify it
Packit e6c7a3
# under the same terms as Perl itself.
Packit e6c7a3
Packit e6c7a3
use strict;
Packit e6c7a3
use warnings;
Packit e6c7a3
Packit e6c7a3
use Test::More tests => 4;
Packit e6c7a3
Packit e6c7a3
# Load the module.
Packit e6c7a3
BEGIN {
Packit e6c7a3
    delete $ENV{ANSI_COLORS_ALIASES};
Packit e6c7a3
    delete $ENV{ANSI_COLORS_DISABLED};
Packit e6c7a3
    use_ok('Term::ANSIColor', qw(:pushpop));
Packit e6c7a3
}
Packit e6c7a3
Packit e6c7a3
# Generate a tainted constant name.  PATH is always tainted, and tainting is
Packit e6c7a3
# sticky, so we can prepend the name to whatever PATH holds and then chop it
Packit e6c7a3
# off again.
Packit e6c7a3
my $constant = substr 'BOLD' . $ENV{PATH}, 0, length 'BOLD';
Packit e6c7a3
Packit e6c7a3
# Using that as a constant should now work without any tainting problems.
Packit e6c7a3
## no critic (TestingAndDebugging::ProhibitNoStrict)
Packit e6c7a3
{
Packit e6c7a3
    no strict 'refs';
Packit e6c7a3
    is(&{$constant}(), "\e[1m", 'Constant subs are not tainted');
Packit e6c7a3
    is(BOLD(),         "\e[1m", '...and we can call the sub again');
Packit e6c7a3
    ok(defined(&Term::ANSIColor::BOLD), '...and it is now defined');
Packit e6c7a3
}