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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
repeat_each(2);
plan tests => repeat_each() * 2 * blocks();
#no_long_string();
run_tests();
#no_diff();
__DATA__
=== TEST 1: basic convertion
--- config
location /foo {
set $src '你好';
set_iconv $dst $src from=utf-8 to=gbk;
echo $dst;
}
--- request
GET /foo
--- charset: gbk
--- response_body
你好
=== TEST 2: more complex convertion
--- config
location /foo {
set $src '淘宝网 - 亚洲最大、最安全的网上交易平台,提供各类服饰、美容、家居、数码、话费/点卡充值… 2亿优质特价商品,同时提供担保交易(先收货后付款)、先行赔付、假一赔三、七天无理由退换货、数码免费维修等安全交易保障服务,让你全面安心享受网上购物乐趣!';
set_iconv $dst $src from=UTF-8 to=gbk;
echo $dst;
}
--- request
GET /foo
--- charset: gbk
--- response_body
淘宝网 - 亚洲最大、最安全的网上交易平台,提供各类服饰、美容、家居、数码、话费/点卡充值… 2亿优质特价商品,同时提供担保交易(先收货后付款)、先行赔付、假一赔三、七天无理由退换货、数码免费维修等安全交易保障服务,让你全面安心享受网上购物乐趣!
=== TEST 3: large iconv_buffer_size
--- config
location /foo {
set $src '你好';
iconv_buffer_size 1M;
set_iconv $dst $src from=utf-8 to=GBK;
echo $dst;
}
--- request
GET /foo
--- charset: gbk
--- response_body
你好
=== TEST 4: iconv content filter
--- config
location /foo {
iconv_filter from=utf-8 to=GBK;
echo '你好';
}
--- request
GET /foo
--- charset: gbk
--- response_body
你好
=== TEST 5: content in multi buf
--- config
location /foo {
iconv_filter from=utf-8 to=GBK;
#set_unescape_uri $a $arg_a;
#set_unescape_uri $b $arg_b;
#set_unescape_uri $c $arg_c;
#set_unescape_uri $d $arg_d;
echo -n $arg_a;
echo -n $arg_b;
echo -n $arg_c;
echo $arg_d;
}
--- request
GET /foo?a=你&b=好&c=世&d=界
--- charset: gbk
--- response_body
你好世界
=== TEST 6: content in multi buf
--- config
location /foo {
iconv_filter from=utf-8 to=GBK;
set_unescape_uri $a $arg_a;
set_unescape_uri $b $arg_b;
set_unescape_uri $c $arg_c;
set_unescape_uri $d $arg_d;
set_unescape_uri $e $arg_e;
set_unescape_uri $f $arg_f;
echo -n $a;
echo -n $b;
echo -n $c;
echo -n $d;
echo -n $e;
echo $f;
}
--- request
GET /foo?a=%e4&b=%bd&c=%a0&d=%e5&e=%a5&f=%bd
--- charset: gbk
--- response_body
你好
=== TEST 7: content in multi buf
--- config
location /foo {
iconv_filter from=utf-8 to=GBK;
iconv_buffer_size 1k;
set_unescape_uri $a $arg_a;
set_unescape_uri $b $arg_b;
set_unescape_uri $c $arg_c;
set_unescape_uri $d $arg_d;
set_unescape_uri $e $arg_e;
set_unescape_uri $f $arg_f;
echo -n $a;
echo -n $b;
echo -n $c;
echo -n $d;
echo -n $e;
echo $f;
}
--- request
GET /foo?a=%e4&b=%bd&c=%a0&d=%e5&e=%a5&f=%bd
--- charset: gbk
--- response_body
你好
=== TEST 8: some complex text
--- config
location /foo {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 2;
echo '106,纪梵希 蜜粉,8,4.5,62.5%
107,时空胶囊,8,3.2857142857143,42.86%
108,雅顿 vc 美白 胶囊,8,7,14.29%
109,水磁场,8,5,14.29%
110,GEL,8,1,100%
111,雅顿 润唇膏 正品,8,8,20%
112,玫瑰面膜,8,1.5,87.5%
113,露得清 祛痘,8,5.1428571428571,42.86%
114,美白水,8,4.75,50%
115,ë,8,1.875,87.5%
116,大米粉,8,1.25,75%
350,薇姿油脂调护洁面啫喱,2,1,100%
475,啫喱 屈臣氏,1,1,100%
569,洗面奶啫喱,1,1,100%';
}
--- request
GET /foo
--- charset: gbk
--- response_body
106,纪梵希 蜜粉,8,4.5,62.5%
107,时空胶囊,8,3.2857142857143,42.86%
108,雅顿 vc 美白 胶囊,8,7,14.29%
109,水磁场,8,5,14.29%
110,GEL,8,1,100%
111,雅顿 润唇膏 正品,8,8,20%
112,玫瑰面膜,8,1.5,87.5%
113,露得清 祛痘,8,5.1428571428571,42.86%
114,美白水,8,4.75,50%
115,??,8,1.875,87.5%
116,大米粉,8,1.25,75%
350,薇姿油脂调护洁面啫喱,2,1,100%
475,啫喱 屈臣氏,1,1,100%
569,洗面奶啫喱,1,1,100%
=== TEST 9:
--- config
location /foo {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 10;
echo '106,纪梵希 蜜粉,8,4.5,62.5%
107,时空胶囊,8,3.2857142857143,42.86%
108,雅顿 vc 美白 胶囊,8,7,14.29%
109,水磁场,8,5,14.29%
110,GEL,8,1,100%
111,雅顿 润唇膏 正品,8,8,20%
112,玫瑰面膜,8,1.5,87.5%
113,露得清 祛痘,8,5.1428571428571,42.86%
114,美白水,8,4.75,50%
115,ë,8,1.875,87.5%
116,大米粉,8,1.25,75%
350,薇姿油脂调护洁面啫喱,2,1,100%
475,啫喱 屈臣氏,1,1,100%
569,洗面奶啫喱,1,1,100%';
}
--- request
GET /foo
--- charset: gbk
--- response_body
106,纪梵希 蜜粉,8,4.5,62.5%
107,时空胶囊,8,3.2857142857143,42.86%
108,雅顿 vc 美白 胶囊,8,7,14.29%
109,水磁场,8,5,14.29%
110,GEL,8,1,100%
111,雅顿 润唇膏 正品,8,8,20%
112,玫瑰面膜,8,1.5,87.5%
113,露得清 祛痘,8,5.1428571428571,42.86%
114,美白水,8,4.75,50%
115,??,8,1.875,87.5%
116,大米粉,8,1.25,75%
350,薇姿油脂调护洁面啫喱,2,1,100%
475,啫喱 屈臣氏,1,1,100%
569,洗面奶啫喱,1,1,100%
=== TEST 10: text that can't be converted, buffer size smaller than content
--- config
location /foo {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 2;
echo 'ë?';
}
--- request
GET /foo
--- charset: gbk
--- response_body
???
=== TEST 11: text that can't be converted, buffer size smaller than content
--- config
location /foo {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 2;
echo '?ë';
}
--- request
GET /foo
--- charset: gbk
--- response_body
???
=== TEST 12: text that can't be converted, buffer size smaller than content
--- config
location /foo {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 3;
echo '?ë';
}
--- request
GET /foo
--- charset: gbk
--- response_body
???
=== TEST 13: text that can't be converted, buffer size equals content
--- config
location /foo {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 4;
echo '?ë';
}
--- request
GET /foo
--- charset: gbk
--- response_body
???
=== TEST 14: text that can't be converted, buffer size larger than content
--- config
location /foo {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 5;
echo '?ë';
}
--- request
GET /foo
--- charset: gbk
--- response_body
???
=== TEST 15: iconv_filter used with proxy_pass
--- config
location /foo {
proxy_pass $scheme://127.0.0.1:$server_port/bar;
}
location /bar {
content_by_lua 'ngx.print("这是一段文本")';
iconv_filter from=utf-8 to=gbk;
}
--- request
GET /foo
--- charset: gbk
--- response_body chop
这是一段文本
=== TEST 16: iconv content filter / HTTP 1.0
--- config
location /foo {
iconv_filter from=utf-8 to=GBK;
echo '你好';
}
--- request
GET /foo HTTP/1.0
--- charset: gbk
--- response_body
你好
=== TEST 17: iconv used together with proxy
--- config
location /data.txt {
iconv_filter from=utf8 to=gbk;
}
location /proxy {
proxy_pass $scheme://127.0.0.1:$server_port/data.txt;
}
--- user_files
>>> data.txt
你好
--- request
GET /proxy
--- charset: gbk
--- response_body
你好
=== TEST 18: iconv_filter used with proxy_pass
--- config
location /foo {
proxy_pass $scheme://127.0.0.1:$server_port/bar;
iconv_filter from=utf-8 to=gbk;
}
location /bar {
content_by_lua 'ngx.print("这是一段文本")';
}
--- request
GET /foo
--- charset: gbk
--- response_body chop
这是一段文本
=== TEST 19: iconv_filter used with proxy_pass
--- config
location /main {
content_by_lua '
local res = ngx.location.capture("/foo")
ngx.print(res.body)
';
}
location /foo {
iconv_filter from=utf-8 to=gbk;
proxy_pass $scheme://127.0.0.1:$server_port/bar;
}
location /bar {
content_by_lua 'ngx.print("这是一段文本")';
}
--- request
GET /main
--- charset: gbk
--- response_body chop
这是一段文本
=== TEST 20: iconv_filter used with proxy_pass
--- config
location /foo {
#set_form_input $data;
proxy_pass $scheme://127.0.0.1:$server_port/bar;
proxy_http_version 1.0;
#echo $data;
}
location /bar {
echo -n "你好";
iconv_filter from=utf-8 to=gbk;
}
--- more_headers
Content-Type: application/x-www-form-urlencoded
--- request
GET /foo
--- charset: gbk
--- response_body chop
你好
|