@@ -4,43 +4,43 @@ import { encode } from "iconv-lite"
4
4
import convertBody from "./src"
5
5
6
6
test ( "should support encoding decode, xml dtd detect" , ( t ) => {
7
- const text = "<?xml version=\"1.0\" encoding=\"EUC-JP\"?><title>日本語</title>"
8
- t . is ( convertBody ( encode ( text , "EUC-JP" ) , new Headers ( { "Content-Type" : "text/xml" } ) ) , text )
7
+ const text = "<?xml version=\"1.0\" encoding=\"EUC-JP\"?><title>日本語</title>"
8
+ t . is ( convertBody ( encode ( text , "EUC-JP" ) , new Headers ( { "Content-Type" : "text/xml" } ) ) , text )
9
9
} )
10
10
11
11
test ( "should support encoding decode, content-type detect" , ( t ) => {
12
- const text = "<div>日本語</div>"
13
- t . is ( convertBody ( encode ( text , "Shift_JIS" ) , new Headers ( { "Content-Type" : "text/html; charset=Shift-JIS" } ) ) , text )
12
+ const text = "<div>日本語</div>"
13
+ t . is ( convertBody ( encode ( text , "Shift_JIS" ) , new Headers ( { "Content-Type" : "text/html; charset=Shift-JIS" } ) ) , text )
14
14
} )
15
15
16
16
test ( "should support encoding decode, html5 detect" , ( t ) => {
17
- const text = "<meta charset=\"gbk\"><div>中文</div>"
18
- t . is ( convertBody ( encode ( text , "gbk" ) , new Headers ( { "Content-Type" : "text/html" } ) ) , text )
17
+ const text = "<meta charset=\"gbk\"><div>中文</div>"
18
+ t . is ( convertBody ( encode ( text , "gbk" ) , new Headers ( { "Content-Type" : "text/html" } ) ) , text )
19
19
} )
20
20
21
21
test ( "should support encoding decode, html4 detect" , ( t ) => {
22
- const text = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"><div>中文</div>"
23
- t . is ( convertBody ( encode ( text , "gb2312" ) , new Headers ( { "Content-Type" : "text/html" } ) ) , text )
22
+ const text = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"><div>中文</div>"
23
+ t . is ( convertBody ( encode ( text , "gb2312" ) , new Headers ( { "Content-Type" : "text/html" } ) ) , text )
24
24
} )
25
25
26
26
test ( "should default to utf8 encoding" , ( t ) => {
27
- const text = "中文"
28
- t . is ( convertBody ( text ) , text )
27
+ const text = "中文"
28
+ t . is ( convertBody ( text ) , text )
29
29
} )
30
30
31
31
test ( "should support uncommon content-type order, end with qs" , ( t ) => {
32
- const text = "中文"
33
- t . is ( convertBody ( encode ( text , "gbk" ) , new Headers ( { "Content-Type" : "text/plain; charset=gbk; qs=1" } ) ) , text )
32
+ const text = "中文"
33
+ t . is ( convertBody ( encode ( text , "gbk" ) , new Headers ( { "Content-Type" : "text/plain; charset=gbk; qs=1" } ) ) , text )
34
34
} )
35
35
36
36
test ( "should support chunked encoding, html4 detect" , ( t ) => {
37
- const text = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" /><div>日本語</div>"
38
- const padding = "a" . repeat ( 10 )
39
- t . is ( convertBody ( encode ( padding + text , "Shift_JIS" ) , new Headers ( { "Content-Type" : "text/html" , "Transfer-Encoding" : "chunked" } ) ) , padding + text )
37
+ const text = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\" /><div>日本語</div>"
38
+ const padding = "a" . repeat ( 10 )
39
+ t . is ( convertBody ( encode ( padding + text , "Shift_JIS" ) , new Headers ( { "Content-Type" : "text/html" , "Transfer-Encoding" : "chunked" } ) ) , padding + text )
40
40
} )
41
41
42
42
test ( "should only do encoding detection up to 1024 bytes" , ( t ) => {
43
- const text = "中文"
44
- const padding = "a" . repeat ( 1200 )
45
- t . not ( convertBody ( encode ( padding + text , "gbk" ) , new Headers ( { "Content-Type" : "text/html" , "Transfer-Encoding" : "chunked" } ) ) , text )
43
+ const text = "中文"
44
+ const padding = "a" . repeat ( 1200 )
45
+ t . not ( convertBody ( encode ( padding + text , "gbk" ) , new Headers ( { "Content-Type" : "text/html" , "Transfer-Encoding" : "chunked" } ) ) , text )
46
46
} )
0 commit comments