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
28 ["=30\n" => "=3D30\n"],
29 ["\0\xff0" => "=00=FF0"],
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!234567" => "$x70!2345=\n67"],
61 ["$x70!23456=" => "$x70!2345=\n6=3D"],
62 ["$x70!23\n" => "$x70!23\n"],
63 ["$x70!234\n" => "$x70!234\n"],
64 ["$x70!2345\n" => "$x70!2345\n"],
65 ["$x70!23456\n" => "$x70!23456\n"],
66 ["$x70!234567\n" => "$x70!2345=\n67\n"],
67 ["$x70!23456=\n" => "$x70!2345=\n6=3D\n"],
69 # Not allowed to break =XX escapes using soft line break
70 ["$x70===xxxxx" => "$x70=3D=\n=3D=3Dxxxxx"],
71 ["$x70!===xxxx" => "$x70!=3D=\n=3D=3Dxxxx"],
72 ["$x70!2===xxx" => "$x70!2=3D=\n=3D=3Dxxx"],
73 ["$x70!23===xx" => "$x70!23=\n=3D=3D=3Dxx"],
74 ["$x70!234===x" => "$x70!234=\n=3D=3D=3Dx"],
75 ["$x70!2=\n" => "$x70!2=3D\n"],
76 ["$x70!23=\n" => "$x70!23=\n=3D\n"],
77 ["$x70!234=\n" => "$x70!234=\n=3D\n"],
78 ["$x70!2345=\n" => "$x70!2345=\n=3D\n"],
79 ["$x70!23456=\n" => "$x70!2345=\n6=3D\n"],
85 # some extra special cases we have had problems with
86 ["$x70!2=x=x" => "$x70!2=3D=\nx=3Dx"],
87 ["$x70!2345$x70!2345$x70!23456\n", "$x70!2345=\n$x70!2345=\n$x70!23456\n"],
90 $notests = @tests + 3;
91 print "1..$notests\n";
96 ($plain, $encoded) = @$_;
97 if (ord('A') == 193) { # EBCDIC 8 bit chars are different
98 if ($testno == 2) { $plain =~ s/\xe5/\x47/; $plain =~ s/\xe6/\x9c/g; $plain =~ s/\xf8/\x70/; }
99 if ($testno == 7) { $plain =~ s/\xff/\xdf/; }
101 $x = encode_qp($plain);
102 if ($x ne $encoded) {
103 print "Encode test failed\n";
105 print "Expected: '$encoded'\n";
106 print "not ok $testno\n";
109 $x = decode_qp($encoded);
111 print "Decode test failed\n";
113 print "Expected: '$plain'\n";
114 print "not ok $testno\n";
117 print "ok $testno\n";
120 # Some extra testing for a case that was wrong until libwww-perl-5.09
121 print "not " unless decode_qp("foo \n\nfoo =\n\nfoo=20\n\n") eq
122 "foo\n\nfoo \nfoo \n\n";
123 $testno++; print "ok $testno\n";
125 # Same test but with "\r\n" terminated lines
126 print "not " unless decode_qp("foo \r\n\r\nfoo =\r\n\r\nfoo=20\r\n\r\n") eq
127 "foo\n\nfoo \nfoo \n\n";
128 $testno++; print "ok $testno\n";
130 print "not " if $] >= 5.006 && (eval 'encode_qp("XXX \x{100}")' || !$@);
131 $testno++; print "ok $testno\n";