File: ParamVal.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 (62 lines) | stat: -rw-r--r-- 1,897 bytes parent folder | download | duplicates (4)
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
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;
use Test::More tests => 13;

use MIME::Field::ContType;
use MIME::WordDecoder;

use Encode;

# Trivial test
{
	my $field = Mail::Field->new('Content-type');

	isa_ok( $field, 'MIME::Field::ParamVal');
	isa_ok( $field, 'Mail::Field');

	$field->param('_', 'stuff');
	$field->param('answer', 42);

	is( $field->stringify, 'stuff; answer="42"', 'Object stringified to expected value');
}

# Test for CPAN RT #34451
{
	my $header = 'stuff; answer*=utf-8\'\'%c3%be%20%c3%bf';

	my $field = Mail::Field->new('Content-type');
	$field->parse( $header );
	is( $field->param('_'), 'stuff', 'Got body of header');

	# We get it back in UTF-8!
	my $expected = pack('CCCCC', 0xc3, 0xbe, 0x20, 0xc3, 0xbf);
	my $wd = supported MIME::WordDecoder 'UTF-8';

	is( encode('utf8', $wd->decode($field->param('answer'))), $expected, 'answer param was unpacked correctly');
}

# Test for CPAN RT #105455
{
	my $header = 'attachment; filename=wookie.zip size=3; junk=cabbage';

	my $field = Mail::Field->new('Content-type');
	$field->parse( $header );
	is( $field->param('_'), 'attachment', 'Got body of header');
	is ($field->param('filename'), 'wookie.zip', 'Got correct filename');
	is ($field->param('junk'), 'cabbage', 'Got correct final param');

	$header = 'attachment; filename="wookie.zip size=3"';

	$field = Mail::Field->new('Content-type');
	$field->parse( $header );
	is( $field->param('_'), 'attachment', 'Got body of header');
	is ($field->param('filename'), 'wookie.zip size=3', 'Got correct filename');

	$header = 'attachment; filename="wookie.zip;x=1"; (crap); (more_crap) adhesive=glueme';

	$field = Mail::Field->new('Content-type');
	$field->parse( $header );
	is( $field->param('_'), 'attachment', 'Got body of header');
	is ($field->param('filename'), 'wookie.zip;x=1', 'Got correct filename');
	is ($field->param('adhesive'), 'glueme', 'Got correct final parameter');
}