14 # plain ascii should not be encoded
15 ["quoted printable" =>
18 # 8-bit chars should be encoded
19 ["v\xe5re kj\xe6re norske tegn b\xf8r \xe6res" =>
20 "v=E5re kj=E6re norske tegn b=F8r =E6res"],
22 # trailing space should be encoded
24 ["\tt\t" => "\tt=09"],
25 ["test \ntest\n\t \t \n" => "test=20=20\ntest\n=09=20=09=20\n"],
27 # "=" is special an should be decoded
29 ["\0\xff" => "=00=FF"],
31 # Very long lines should be broken (not more than 76 chars
32 ["The Quoted-Printable encoding is intended to represent data that largly consists of octets that correspond to printable characters in the ASCII character set." =>
33 "The Quoted-Printable encoding is intended to represent data that largly con=
34 sists of octets that correspond to printable characters in the ASCII charac=
38 # Long lines after short lines were broken through 2.01.
40 In America, any boy may become president and I suppose that's just one of the risks he takes. -- Adlai Stevenson" =>
42 In America, any boy may become president and I suppose that's just one of t=
43 he risks he takes. -- Adlai Stevenson"],
45 # My (roderick@argon.org) first crack at fixing that bug failed for
46 # multiple long lines.
47 ["College football is a game which would be much more interesting if the faculty played instead of the students, and even more interesting if the
48 trustees played. There would be a great increase in broken arms, legs, and necks, and simultaneously an appreciable diminution in the loss to humanity. -- H. L. Mencken" =>
49 "College football is a game which would be much more interesting if the facu=
50 lty played instead of the students, and even more interesting if the
51 trustees played. There would be a great increase in broken arms, legs, and=
52 necks, and simultaneously an appreciable diminution in the loss to humanit=
53 y. -- H. L. Mencken"],
55 # Don't break a line that's near but not over 76 chars.
56 ["$x70!23" => "$x70!23"],
57 ["$x70!234" => "$x70!234"],
58 ["$x70!2345" => "$x70!2345"],
59 ["$x70!23456" => "$x70!23456"],
60 ["$x70!23\n" => "$x70!23\n"],
61 ["$x70!234\n" => "$x70!234\n"],
62 ["$x70!2345\n" => "$x70!2345\n"],
63 ["$x70!23456\n" => "$x70!23456\n"],
65 # Not allowed to break =XX escapes using soft line break
66 ["$x70===xxxx" => "$x70=3D=\n=3D=3Dxxxx"],
67 ["$x70!===xxx" => "$x70!=3D=\n=3D=3Dxxx"],
68 ["$x70!!===xx" => "$x70!!=3D=\n=3D=3Dxx"],
69 ["$x70!!!===x" => "$x70!!!=\n=3D=3D=3Dx"],
76 $notests = @tests + 3;
77 print "1..$notests\n";
82 ($plain, $encoded) = @$_;
83 if (ord('A') == 193) { # EBCDIC 8 bit chars are different
84 if ($testno == 2) { $plain =~ s/\xe5/\x47/; $plain =~ s/\xe6/\x9c/g; $plain =~ s/\xf8/\x70/; }
85 if ($testno == 7) { $plain =~ s/\xff/\xdf/; }
87 $x = encode_qp($plain);
89 print "Encode test failed\n";
91 print "Expected: '$encoded'\n";
92 print "not ok $testno\n";
95 $x = decode_qp($encoded);
97 print "Decode test failed\n";
99 print "Expected: '$plain'\n";
100 print "not ok $testno\n";
103 print "ok $testno\n";
106 # Some extra testing for a case that was wrong until libwww-perl-5.09
107 print "not " unless decode_qp("foo \n\nfoo =\n\nfoo=20\n\n") eq
108 "foo\n\nfoo \nfoo \n\n";
109 $testno++; print "ok $testno\n";
111 # Same test but with "\r\n" terminated lines
112 print "not " unless decode_qp("foo \r\n\r\nfoo =\r\n\r\nfoo=20\r\n\r\n") eq
113 "foo\r\n\r\nfoo \r\nfoo \r\n\r\n";
114 $testno++; print "ok $testno\n";
116 print "not " if $] >= 5.006 && (eval 'encode_qp("XXX \x{100}")' || $@ !~ /^The Quoted-Printable encoding is only defined for bytes/);
117 $testno++; print "ok $testno\n";