File: Filer.t

package info (click to toggle)
libmime-tools-perl 5.515-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,612 kB
  • sloc: perl: 6,349; makefile: 8
file content (50 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 17;

use Config;

binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
binmode( Test::More->builder()->output(), ':encoding(utf-8)' );

# Perl < 5.10.0 did not handle Unicode at all...
my $wookie;

if ($Config{'PERL_REVISION'} == 5 &&
    $Config{'PERL_VERSION'} <= 8) {
	$wookie = 'wookie%D0.doc';
} else {
	$wookie = 'wookie%42D.doc';
}

BEGIN {
	use_ok('MIME::Parser::Filer');
}

# Tests for CPAN ticket 6789, and others
{
	my $filer = MIME::Parser::Filer->new();

	# All of these filenames should be considered evil
	my %evil = (
		' '               => '.dat' ,
		' leading_space'  => 'leading_space.dat',
		'trailing_space ' => 'trailing_space.dat',
		'.'               => '..dat',
		'..'              => '...dat',
		'index[1].html'   => 'index_1_.html',
		" wookie\x{f8}.doc" => "wookie%F8.doc",
		" wookie\x{042d}.doc" => $wookie,
	);

	foreach my $name (keys %evil) {
		ok( $filer->evil_filename( $name ), "$name is evil");
	}

	while( my ($evil, $clean) = each %evil ) {
		is( $filer->exorcise_filename( $evil), $clean, "$evil was exorcised");
	}

}