forked from lifenjoiner/wget-for-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest-iri.px
executable file
·254 lines (227 loc) · 6.45 KB
/
Test-iri.px
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env perl
use strict;
use warnings;
use WgetFeature qw(iri);
use HTTPTest;
use Encode::Locale;
use Encode::Locale qw($ENCODING_LOCALE $ENCODING_CONSOLE_IN $ENCODING_CONSOLE_OUT);
use Encode;
# cf. http://en.wikipedia.org/wiki/Latin1
# http://en.wikipedia.org/wiki/ISO-8859-15
###############################################################################
#
# mime : charset found in Content-Type HTTP MIME header
# meta : charset found in Content-Type meta tag
#
# index.html mime + file = iso-8859-15
# p1_français.html meta + file = iso-8859-1, mime = utf-8
# p2_één.html meta + file = utf-8, mime =iso-8859-1
# p3_€€€.html meta + file = utf-8, mime = iso-8859-1
# p4_méér.html mime + file = utf-8
#
my $ccedilla_l15 = "\xE7";
my $ccedilla_u8 = "\xC3\xA7";
my $eacute_l1 = "\xE9";
my $eacute_u8 = "\xC3\xA9";
my $eurosign_l15 = "\xA4";
my $eurosign_u8 = "\xE2\x82\xAC";
my $pageindex = <<EOF;
<html>
<head>
<title>Main Page</title>
</head>
<body>
<p>
Link to page 1 <a href="http://localhost:{{port}}/p1_fran${ccedilla_l15}ais.html">La seule page en français</a>.
Link to page 3 <a href="http://localhost:{{port}}/p3_${eurosign_l15}${eurosign_l15}${eurosign_l15}.html">My tailor is rich</a>.
</p>
</body>
</html>
EOF
# specifying a wrong charset in http-equiv - it will be overridden by Content-Type HTTP header
my $pagefrancais = <<EOF;
<html>
<head>
<title>La seule page en français</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p>
Link to page 2 <a href="http://localhost:{{port}}/p2_${eacute_l1}${eacute_l1}n.html">Die enkele nerderlangstalige pagina</a>.
</p>
</body>
</html>
EOF
my $pageeen = <<EOF;
<html>
<head>
<title>Die enkele nederlandstalige pagina</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p>
Één is niet veel maar toch meer dan nul.<br/>
Nerdelands is een mooie taal... dit zin stuckje spreekt vanzelf, of niet :)<br/>
<a href="http://localhost:{{port}}/p4_m${eacute_u8}${eacute_u8}r.html">Méér</a>
</p>
</body>
</html>
EOF
my $pageeuro = <<EOF;
<html>
<head>
<title>Euro page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p>
My tailor isn't rich anymore.
</p>
</body>
</html>
EOF
my $pagemeer = <<EOF;
<html>
<head>
<title>Bekende supermarkt</title>
</head>
<body>
<p>
Ik ben toch niet gek !
</p>
</body>
</html>
EOF
my $page404 = <<EOF;
<html>
<head>
<title>404</title>
</head>
<body>
<p>
Nop nop nop...
</p>
</body>
</html>
EOF
# code, msg, headers, content
my %urls = (
'/index.html' => {
code => "200",
msg => "Ok",
headers => {
"Content-type" => "text/html; charset=ISO-8859-15",
},
content => $pageindex,
},
'/robots.txt' => {
code => "200",
msg => "Ok",
headers => {
"Content-type" => "text/plain",
},
content => "",
},
'/p1_fran%C3%A7ais.html' => { # UTF-8 encoded
code => "200",
msg => "Ok",
headers => {
# Content-Type header overrides http-equiv Content-Type
"Content-type" => "text/html; charset=ISO-8859-15",
},
content => $pagefrancais,
},
'/p2_%C3%A9%C3%A9n.html' => { # UTF-8 encoded
code => "200",
msg => "Ok",
request_headers => {
"Referer" => qr|http://localhost:[0-9]+/p1_fran%C3%A7ais.html|,
},
headers => {
"Content-type" => "text/html; charset=UTF-8",
},
content => $pageeen,
},
'/p3_%E2%82%AC%E2%82%AC%E2%82%AC.html' => { # UTF-8 encoded
code => "200",
msg => "Ok",
headers => {
"Content-type" => "text/plain; charset=ISO-8859-1",
},
content => $pageeuro,
},
'/p4_m%C3%A9%C3%A9r.html' => {
code => "200",
msg => "Ok",
request_headers => {
"Referer" => qr|http://localhost:[0-9]+/p2_%C3%A9%C3%A9n.html|,
},
headers => {
"Content-type" => "text/plain; charset=UTF-8",
},
content => $pagemeer,
},
);
my $cmdline = $WgetTest::WGETPATH . " --iri --trust-server-names --restrict-file-names=nocontrol -nH -r http://localhost:{{port}}/";
my $expected_error_code = 0;
my $native_encoding = $ENCODING_LOCALE;
# To make the downloaded (OS encoding) to here got (maybe transcoded) the same with expected!
# Encode::Locale::reinit() would make: locale == `locale -n`, but locale != (console_in == console_out)
print "LC_CTYPE: " . ($ENV{'LC_CTYPE'} || "") . "\n"; # ~> wget findlocale()
print "ENCODING_LOCALE: " . $ENCODING_LOCALE . "\n";
print "ENCODING_CONSOLE_IN: " . $ENCODING_CONSOLE_IN . "\n";
print "ENCODING_CONSOLE_OUT: " . $ENCODING_CONSOLE_OUT . "\n";
if ($^O eq "msys" || $^O eq "cygwin") {
use Win32;
$native_encoding = "CP" . Win32::GetACP();
print "native encoding: " . $native_encoding . "\n";
}
sub can_transcode_to_locale
{
my ($from, $str, $to) = @_;
my $m = Encode::encode($to, Encode::decode($from, $str));
return Encode::encode($from, Encode::decode($to, $m)) eq $str;
}
my $p1_out = ${ccedilla_u8};
if (!can_transcode_to_locale("UTF-8", $p1_out, $native_encoding))
{
$p1_out = "%C3%A7";
}
my $p2_out = ${eacute_u8} . ${eacute_u8};
if (!can_transcode_to_locale("UTF-8", $p2_out, $native_encoding))
{
$p2_out = "%C3%A9%C3%A9";
}
my $p3_out = ${eurosign_u8} . ${eurosign_u8} . ${eurosign_u8};
if (!can_transcode_to_locale("UTF-8", $p3_out, $native_encoding))
{
$p3_out = "%E2%82%AC%E2%82%AC%E2%82%AC";
}
my $p4_out = $p2_out;
my %expected_downloaded_files = (
'index.html' => {
content => $pageindex,
},
'robots.txt' => {
content => "",
},
"p1_fran${p1_out}ais.html" => {
content => $pagefrancais,
},
"p2_${p2_out}n.html" => {
content => $pageeen,
},
"p3_${p3_out}.html" => {
content => $pageeuro,
},
"p4_m${p4_out}r.html" => {
content => $pagemeer,
},
);
###############################################################################
my $the_test = HTTPTest->new (input => \%urls,
cmdline => $cmdline,
errcode => $expected_error_code,
output => \%expected_downloaded_files);
exit $the_test->run();
# vim: et ts=4 sw=4