Commit | Line | Data |
af6f229e |
1 | BEGIN { |
b9e0df4c |
2 | if ($ENV{PERL_CORE}) { |
3 | chdir 't' if -d 't'; |
4 | @INC = '../lib'; |
5 | } |
af6f229e |
6 | } |
7 | |
8 | use MIME::QuotedPrint; |
9 | |
10 | $x70 = "x" x 70; |
11 | |
df4d7026 |
12 | $IsASCII = ord('A') == 65; |
13 | $IsEBCDIC = ord('A') == 193; |
14 | |
15 | if ($IsASCII) { |
16 | |
af6f229e |
17 | @tests = |
18 | ( |
19 | # plain ascii should not be encoded |
9e87bee3 |
20 | ["", ""], |
af6f229e |
21 | ["quoted printable" => |
9e87bee3 |
22 | "quoted printable=\n"], |
af6f229e |
23 | |
24 | # 8-bit chars should be encoded |
31b48da6 |
25 | ["v\xe5re kj\xe6re norske tegn b\xf8r \xe6res" => |
9e87bee3 |
26 | "v=E5re kj=E6re norske tegn b=F8r =E6res=\n"], |
af6f229e |
27 | |
28 | # trailing space should be encoded |
9e87bee3 |
29 | [" " => "=20=20=\n"], |
30 | ["\tt\t" => "\tt=09=\n"], |
af6f229e |
31 | ["test \ntest\n\t \t \n" => "test=20=20\ntest\n=09=20=09=20\n"], |
32 | |
33 | # "=" is special an should be decoded |
6a63fb82 |
34 | ["=30\n" => "=3D30\n"], |
9e87bee3 |
35 | ["\0\xff0" => "=00=FF0=\n"], |
af6f229e |
36 | |
37 | # Very long lines should be broken (not more than 76 chars |
38 | ["The Quoted-Printable encoding is intended to represent data that largly consists of octets that correspond to printable characters in the ASCII character set." => |
39 | "The Quoted-Printable encoding is intended to represent data that largly con= |
40 | sists of octets that correspond to printable characters in the ASCII charac= |
9e87bee3 |
41 | ter set.=\n" |
af6f229e |
42 | ], |
43 | |
44 | # Long lines after short lines were broken through 2.01. |
45 | ["short line |
46 | In America, any boy may become president and I suppose that's just one of the risks he takes. -- Adlai Stevenson" => |
47 | "short line |
48 | In America, any boy may become president and I suppose that's just one of t= |
9e87bee3 |
49 | he risks he takes. -- Adlai Stevenson=\n"], |
af6f229e |
50 | |
51 | # My (roderick@argon.org) first crack at fixing that bug failed for |
52 | # multiple long lines. |
53 | ["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 |
54 | 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" => |
55 | "College football is a game which would be much more interesting if the facu= |
56 | lty played instead of the students, and even more interesting if the |
57 | trustees played. There would be a great increase in broken arms, legs, and= |
58 | necks, and simultaneously an appreciable diminution in the loss to humanit= |
9e87bee3 |
59 | y. -- H. L. Mencken=\n"], |
af6f229e |
60 | |
61 | # Don't break a line that's near but not over 76 chars. |
9e87bee3 |
62 | ["$x70!23" => "$x70!23=\n"], |
63 | ["$x70!234" => "$x70!234=\n"], |
64 | ["$x70!2345" => "$x70!2345=\n"], |
9f1a4ec8 |
65 | ["$x70!23456" => "$x70!2345=\n6=\n"], |
9e87bee3 |
66 | ["$x70!234567" => "$x70!2345=\n67=\n"], |
67 | ["$x70!23456=" => "$x70!2345=\n6=3D=\n"], |
af6f229e |
68 | ["$x70!23\n" => "$x70!23\n"], |
69 | ["$x70!234\n" => "$x70!234\n"], |
70 | ["$x70!2345\n" => "$x70!2345\n"], |
71 | ["$x70!23456\n" => "$x70!23456\n"], |
6a63fb82 |
72 | ["$x70!234567\n" => "$x70!2345=\n67\n"], |
73 | ["$x70!23456=\n" => "$x70!2345=\n6=3D\n"], |
af6f229e |
74 | |
75 | # Not allowed to break =XX escapes using soft line break |
9e87bee3 |
76 | ["$x70===xxxxx" => "$x70=3D=\n=3D=3Dxxxxx=\n"], |
77 | ["$x70!===xxxx" => "$x70!=3D=\n=3D=3Dxxxx=\n"], |
78 | ["$x70!2===xxx" => "$x70!2=3D=\n=3D=3Dxxx=\n"], |
79 | ["$x70!23===xx" => "$x70!23=\n=3D=3D=3Dxx=\n"], |
80 | ["$x70!234===x" => "$x70!234=\n=3D=3D=3Dx=\n"], |
9f1a4ec8 |
81 | ["$x70!2=" => "$x70!2=3D=\n"], |
82 | ["$x70!23=" => "$x70!23=\n=3D=\n"], |
83 | ["$x70!234=" => "$x70!234=\n=3D=\n"], |
84 | ["$x70!2345=" => "$x70!2345=\n=3D=\n"], |
85 | ["$x70!23456=" => "$x70!2345=\n6=3D=\n"], |
6a63fb82 |
86 | ["$x70!2=\n" => "$x70!2=3D\n"], |
9f1a4ec8 |
87 | ["$x70!23=\n" => "$x70!23=3D\n"], |
6a63fb82 |
88 | ["$x70!234=\n" => "$x70!234=\n=3D\n"], |
89 | ["$x70!2345=\n" => "$x70!2345=\n=3D\n"], |
90 | ["$x70!23456=\n" => "$x70!2345=\n6=3D\n"], |
91 | # ^ |
92 | # 70123456| |
93 | # max |
94 | # line width |
95 | |
96 | # some extra special cases we have had problems with |
9e87bee3 |
97 | ["$x70!2=x=x" => "$x70!2=3D=\nx=3Dx=\n"], |
6a63fb82 |
98 | ["$x70!2345$x70!2345$x70!23456\n", "$x70!2345=\n$x70!2345=\n$x70!23456\n"], |
2c634edc |
99 | |
100 | # trailing whitespace |
9e87bee3 |
101 | ["foo \t ", "foo=20=09=20=\n"], |
102 | ["foo\t \n \t", "foo=09=20\n=20=09=\n"], |
af6f229e |
103 | ); |
104 | |
df4d7026 |
105 | } elsif ($IsEBCDIC) { |
106 | |
107 | @tests = |
108 | ( |
109 | # plain ascii should not be encoded |
110 | ["", ""], |
111 | ["quoted printable" => |
112 | "quoted printable=\n"], |
113 | |
114 | # 8-bit chars should be encoded |
115 | ["v\x47re kj\x9cre norske tegn b\x70r \x47res" => |
116 | "v=47re kj=9Cre norske tegn b=70r =47res=\n"], |
117 | |
118 | # trailing space should be encoded |
119 | [" " => "=40=40=\n"], |
120 | ["\tt\t" => "\tt=05=\n"], |
121 | ["test \ntest\n\t \t \n" => "test=40=40\ntest\n=05=40=05=40\n"], |
122 | |
123 | # "=" is special an should be decoded |
124 | ["=30\n" => "=7E30\n"], |
125 | ["\0\xff0" => "=00=FF0=\n"], |
126 | |
127 | # Very long lines should be broken (not more than 76 chars |
128 | ["The Quoted-Printable encoding is intended to represent data that largly consists of octets that correspond to printable characters in the ASCII character set." => |
129 | "The Quoted-Printable encoding is intended to represent data that largly con= |
130 | sists of octets that correspond to printable characters in the ASCII charac= |
131 | ter set.=\n" |
132 | ], |
133 | |
134 | # Long lines after short lines were broken through 2.01. |
135 | ["short line |
136 | In America, any boy may become president and I suppose that's just one of the risks he takes. -- Adlai Stevenson" => |
137 | "short line |
138 | In America, any boy may become president and I suppose that's just one of t= |
139 | he risks he takes. -- Adlai Stevenson=\n"], |
140 | |
141 | # My (roderick@argon.org) first crack at fixing that bug failed for |
142 | # multiple long lines. |
143 | ["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 |
144 | 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" => |
145 | "College football is a game which would be much more interesting if the facu= |
146 | lty played instead of the students, and even more interesting if the |
147 | trustees played. There would be a great increase in broken arms, legs, and= |
148 | necks, and simultaneously an appreciable diminution in the loss to humanit= |
149 | y. -- H. L. Mencken=\n"], |
150 | |
151 | # Don't break a line that's near but not over 76 chars. |
152 | ["$x70!23" => "$x70!23=\n"], |
153 | ["$x70!234" => "$x70!234=\n"], |
154 | ["$x70!2345" => "$x70!2345=\n"], |
9f1a4ec8 |
155 | ["$x70!23456" => "$x70!2345=\n6=\n"], |
df4d7026 |
156 | ["$x70!234567" => "$x70!2345=\n67=\n"], |
157 | ["$x70!23456=" => "$x70!2345=\n6=7E=\n"], |
158 | ["$x70!23\n" => "$x70!23\n"], |
159 | ["$x70!234\n" => "$x70!234\n"], |
160 | ["$x70!2345\n" => "$x70!2345\n"], |
161 | ["$x70!23456\n" => "$x70!23456\n"], |
162 | ["$x70!234567\n" => "$x70!2345=\n67\n"], |
163 | ["$x70!23456=\n" => "$x70!2345=\n6=7E\n"], |
164 | |
165 | # Not allowed to break =XX escapes using soft line break |
166 | ["$x70===xxxxx" => "$x70=7E=\n=7E=7Exxxxx=\n"], |
167 | ["$x70!===xxxx" => "$x70!=7E=\n=7E=7Exxxx=\n"], |
168 | ["$x70!2===xxx" => "$x70!2=7E=\n=7E=7Exxx=\n"], |
169 | ["$x70!23===xx" => "$x70!23=\n=7E=7E=7Exx=\n"], |
170 | ["$x70!234===x" => "$x70!234=\n=7E=7E=7Ex=\n"], |
171 | ["$x70!2=\n" => "$x70!2=7E\n"], |
172 | ["$x70!23=\n" => "$x70!23=\n=7E\n"], |
173 | ["$x70!234=\n" => "$x70!234=\n=7E\n"], |
174 | ["$x70!2345=\n" => "$x70!2345=\n=7E\n"], |
175 | ["$x70!23456=\n" => "$x70!2345=\n6=7E\n"], |
176 | # ^ |
177 | # 70123456| |
178 | # max |
179 | # line width |
180 | |
181 | # some extra special cases we have had problems with |
182 | ["$x70!2=x=x" => "$x70!2=7E=\nx=7Ex=\n"], |
183 | ["$x70!2345$x70!2345$x70!23456\n", "$x70!2345=\n$x70!2345=\n$x70!23456\n"], |
184 | |
185 | # trailing whitespace |
186 | ["foo \t ", "foo=40=05=40=\n"], |
187 | ["foo\t \n \t", "foo=05=40\n=40=05=\n"], |
188 | ); |
189 | |
190 | } else { |
191 | die sprintf "Unknown character set: ord('A') == %d\n", ord('A'); |
192 | } |
193 | |
9e87bee3 |
194 | $notests = @tests + 16; |
af6f229e |
195 | print "1..$notests\n"; |
196 | |
197 | $testno = 0; |
198 | for (@tests) { |
199 | $testno++; |
200 | ($plain, $encoded) = @$_; |
95635e5f |
201 | if (ord('A') == 193) { # EBCDIC 8 bit chars are different |
202 | if ($testno == 2) { $plain =~ s/\xe5/\x47/; $plain =~ s/\xe6/\x9c/g; $plain =~ s/\xf8/\x70/; } |
203 | if ($testno == 7) { $plain =~ s/\xff/\xdf/; } |
204 | } |
af6f229e |
205 | $x = encode_qp($plain); |
206 | if ($x ne $encoded) { |
207 | print "Encode test failed\n"; |
208 | print "Got: '$x'\n"; |
209 | print "Expected: '$encoded'\n"; |
210 | print "not ok $testno\n"; |
211 | next; |
212 | } |
213 | $x = decode_qp($encoded); |
214 | if ($x ne $plain) { |
215 | print "Decode test failed\n"; |
216 | print "Got: '$x'\n"; |
217 | print "Expected: '$plain'\n"; |
218 | print "not ok $testno\n"; |
219 | next; |
220 | } |
221 | print "ok $testno\n"; |
222 | } |
223 | |
df4d7026 |
224 | if ($IsASCII) { |
225 | |
af6f229e |
226 | # Some extra testing for a case that was wrong until libwww-perl-5.09 |
227 | print "not " unless decode_qp("foo \n\nfoo =\n\nfoo=20\n\n") eq |
228 | "foo\n\nfoo \nfoo \n\n"; |
229 | $testno++; print "ok $testno\n"; |
230 | |
231 | # Same test but with "\r\n" terminated lines |
232 | print "not " unless decode_qp("foo \r\n\r\nfoo =\r\n\r\nfoo=20\r\n\r\n") eq |
6a63fb82 |
233 | "foo\n\nfoo \nfoo \n\n"; |
af6f229e |
234 | $testno++; print "ok $testno\n"; |
235 | |
2c634edc |
236 | # Trailing whitespace |
237 | print "not " unless decode_qp("foo ") eq "foo "; |
238 | $testno++; print "ok $testno\n"; |
239 | |
240 | print "not " unless decode_qp("foo \n") eq "foo\n"; |
241 | $testno++; print "ok $testno\n"; |
242 | |
ea0e37e4 |
243 | print "not " unless decode_qp("foo = \t\x20\nbar\t\x20\n") eq "foo bar\n"; |
244 | $testno++; print "ok $testno\n"; |
245 | |
246 | print "not " unless decode_qp("foo = \t\x20\r\nbar\t\x20\r\n") eq "foo bar\n"; |
247 | $testno++; print "ok $testno\n"; |
248 | |
249 | print "not " unless decode_qp("foo = \t\x20\n") eq "foo "; |
250 | $testno++; print "ok $testno\n"; |
251 | |
252 | print "not " unless decode_qp("foo = \t\x20\r\n") eq "foo "; |
253 | $testno++; print "ok $testno\n"; |
254 | |
255 | print "not " unless decode_qp("foo = \t\x20y\r\n") eq "foo = \t\x20y\n"; |
256 | $testno++; print "ok $testno\n"; |
257 | |
258 | print "not " unless decode_qp("foo =xy\n") eq "foo =xy\n"; |
259 | $testno++; print "ok $testno\n"; |
260 | |
2c634edc |
261 | # Test with with alternative line break |
262 | print "not " unless encode_qp("$x70!2345$x70\n", "***") eq "$x70!2345=***$x70***"; |
263 | $testno++; print "ok $testno\n"; |
264 | |
265 | # Test with no line breaks |
266 | print "not " unless encode_qp("$x70!2345$x70\n", "") eq "$x70!2345$x70=0A"; |
267 | $testno++; print "ok $testno\n"; |
268 | |
9e87bee3 |
269 | # Test binary encoding |
270 | print "not " unless encode_qp("foo", undef, 1) eq "foo=\n"; |
271 | $testno++; print "ok $testno\n"; |
272 | |
273 | print "not " unless encode_qp("foo\nbar\r\n", undef, 1) eq "foo=0Abar=0D=0A=\n"; |
274 | $testno++; print "ok $testno\n"; |
275 | |
276 | print "not " unless encode_qp(join("", map chr, 0..255), undef, 1) eq <<'EOT'; $testno++; print "ok $testno\n"; |
277 | =00=01=02=03=04=05=06=07=08=09=0A=0B=0C=0D=0E=0F=10=11=12=13=14=15=16=17=18= |
278 | =19=1A=1B=1C=1D=1E=1F !"#$%&'()*+,-./0123456789:;<=3D>?@ABCDEFGHIJKLMNOPQRS= |
279 | TUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~=7F=80=81=82=83=84=85=86=87=88= |
280 | =89=8A=8B=8C=8D=8E=8F=90=91=92=93=94=95=96=97=98=99=9A=9B=9C=9D=9E=9F=A0=A1= |
281 | =A2=A3=A4=A5=A6=A7=A8=A9=AA=AB=AC=AD=AE=AF=B0=B1=B2=B3=B4=B5=B6=B7=B8=B9=BA= |
282 | =BB=BC=BD=BE=BF=C0=C1=C2=C3=C4=C5=C6=C7=C8=C9=CA=CB=CC=CD=CE=CF=D0=D1=D2=D3= |
283 | =D4=D5=D6=D7=D8=D9=DA=DB=DC=DD=DE=DF=E0=E1=E2=E3=E4=E5=E6=E7=E8=E9=EA=EB=EC= |
284 | =ED=EE=EF=F0=F1=F2=F3=F4=F5=F6=F7=F8=F9=FA=FB=FC=FD=FE=FF= |
285 | EOT |
286 | |
6a63fb82 |
287 | print "not " if $] >= 5.006 && (eval 'encode_qp("XXX \x{100}")' || !$@); |
b1387238 |
288 | $testno++; print "ok $testno\n"; |
df4d7026 |
289 | |
290 | } elsif ($IsEBCDIC) { |
291 | |
292 | # Some extra testing for a case that was wrong until libwww-perl-5.05 |
293 | print "not " unless decode_qp("foo \n\nfoo =\n\nfoo=40\n\n") eq |
294 | "foo\n\nfoo \nfoo \n\n"; |
295 | $testno++; print "ok $testno\n"; |
296 | |
297 | # Same test but with "\r\n" terminated lines |
298 | print "not " unless decode_qp("foo \r\n\r\nfoo =\r\n\r\nfoo=40\r\n\r\n") eq |
299 | "foo\n\nfoo \nfoo \n\n"; |
300 | $testno++; print "ok $testno\n"; |
301 | |
302 | # Trailing whitespace |
303 | print "not " unless decode_qp("foo ") eq "foo "; |
304 | $testno++; print "ok $testno\n"; |
305 | |
306 | print "not " unless decode_qp("foo \n") eq "foo\n"; |
307 | $testno++; print "ok $testno\n"; |
308 | |
309 | print "not " unless decode_qp("foo = \t\x40\nbar\t\x40\n") eq "foo bar\n"; |
310 | $testno++; print "ok $testno\n"; |
311 | |
312 | print "not " unless decode_qp("foo = \t\x40\r\nbar\t\x40\r\n") eq "foo bar\n"; |
313 | $testno++; print "ok $testno\n"; |
314 | |
315 | print "not " unless decode_qp("foo = \t\x40\n") eq "foo "; |
316 | $testno++; print "ok $testno\n"; |
317 | |
318 | print "not " unless decode_qp("foo = \t\x40\r\n") eq "foo "; |
319 | $testno++; print "ok $testno\n"; |
320 | |
321 | print "not " unless decode_qp("foo = \t\x40y\r\n") eq "foo = \t\x40y\n"; |
322 | $testno++; print "ok $testno\n"; |
323 | |
324 | print "not " unless decode_qp("foo =xy\n") eq "foo =xy\n"; |
325 | $testno++; print "ok $testno\n"; |
326 | |
327 | # Test with with alternative line break |
328 | print "not " unless encode_qp("$x70!2345$x70\n", "***") eq "$x70!2345=***$x70***"; |
329 | $testno++; print "ok $testno\n"; |
330 | |
331 | # Test with no line breaks |
332 | print "not " unless encode_qp("$x70!2345$x70\n", "") eq "$x70!2345$x70=15"; |
333 | $testno++; print "ok $testno\n"; |
334 | |
335 | # Test binary encoding |
336 | print "not " unless encode_qp("foo", undef, 1) eq "foo=\n"; |
337 | $testno++; print "ok $testno\n"; |
338 | |
339 | print "not " unless encode_qp("foo\nbar\r\n", undef, 1) eq "foo=15bar=0D=15=\n"; |
340 | $testno++; print "ok $testno\n"; |
341 | |
342 | print "not " unless encode_qp(join("", map chr, 0..255), undef, 1) eq <<'EOT'; $testno++; print "ok $testno\n"; |
343 | =00=01=02=03=04=05=06=07=08=09=0A=0B=0C=0D=0E=0F=10=11=12=13=14=15=16=17=18= |
344 | =19=1A=1B=1C=1D=1E=1F=20=21=22=23=24=25=26=27=28=29=2A=2B=2C=2D=2E=2F=30=31= |
345 | =32=33=34=35=36=37=38=39=3A=3B=3C=3D=3E=3F =41=42=43=44=45=46=47=48=49=4A.<= |
346 | (+|&=51=52=53=54=55=56=57=58=59!$*);^-/=62=63=64=65=66=67=68=69=6A,%_>?=70= |
347 | =71=72=73=74=75=76=77=78`:#@'=7E"=80abcdefghi=8A=8B=8C=8D=8E=8F=90jklmnopqr= |
348 | =9A=9B=9C=9D=9E=9F=A0~stuvwxyz=AA=AB=AC=AD=AE=AF=B0=B1=B2=B3=B4=B5=B6=B7=B8= |
349 | =B9=BA=BB=BC=BD=BE=BF{ABCDEFGHI=CA=CB=CC=CD=CE=CF}JKLMNOPQR=DA=DB=DC=DD=DE= |
350 | =DF\=E1STUVWXYZ=EA=EB=EC=ED=EE=EF0123456789=FA=FB=FC=FD=FE=FF= |
351 | EOT |
352 | |
353 | print "not " if $] >= 5.006 && (eval 'encode_qp("XXX \x{100}")' || !$@); |
354 | $testno++; print "ok $testno\n"; |
355 | |
356 | } |
357 | |