This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Encode from version 2.67 to 2.68
[perl5.git] / cpan / Encode / t / taint.t
1 #!/usr/bin/perl -T
2 use strict;
3 use Encode qw(encode decode);
4 use Scalar::Util qw(tainted);
5 use Test::More;
6 my $taint = substr($ENV{PATH},0,0);
7 my $str = "dan\x{5f3e}" . $taint;                 # tainted string to encode
8 my $bin = encode('UTF-8', $str);                  # tainted binary to decode
9 my @names = Encode->encodings(':all');
10 plan tests => 2 * @names;
11 for my $name (@names) {
12     my ($d, $e, $s);
13     eval {
14         $e = encode($name, $str);
15     };
16   SKIP: {
17       skip $@, 1 if $@;
18       ok tainted($e), "encode $name";
19     }
20     $bin = $e.$taint if $e;
21     eval {
22         $d = decode($name, $bin);
23     };
24   SKIP: {
25       skip $@, 1 if $@;
26       ok tainted($d), "decode $name";
27     }
28 }