File tree 4 files changed +27
-0
lines changed
4 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,12 @@ const convertBody = (buffer, headers) => {
293
293
if ( ! res && str ) {
294
294
res = / < m e t a [ \s ] + ?h t t p - e q u i v = ( [ ' " ] ) c o n t e n t - t y p e \1[ \s ] + ?c o n t e n t = ( [ ' " ] ) ( .+ ?) \2/ i. exec ( str )
295
295
296
+ if ( ! res ) {
297
+ res = / < m e t a [ \s ] + ?c o n t e n t = ( [ ' " ] ) ( .+ ?) \1[ \s ] + ?h t t p - e q u i v = ( [ ' " ] ) c o n t e n t - t y p e \3/ i. exec ( str )
298
+ if ( res )
299
+ res . pop ( ) // drop last quote
300
+ }
301
+
296
302
if ( res )
297
303
res = / c h a r s e t = ( .* ) / i. exec ( res . pop ( ) )
298
304
}
Original file line number Diff line number Diff line change @@ -307,6 +307,13 @@ t.test('convert body', t => {
307
307
t . equal ( await b . textConverted ( ) , s )
308
308
} )
309
309
310
+ t . test ( 'html4 meta tag reversed' , async t => {
311
+ const s = '<meta content="text/html; charset=gbk" http-equiv="Content-Type"><div>中文L</div>'
312
+ const b = new Body ( convert ( s , 'gbk' ) )
313
+ t . equal ( await b . textConverted ( ) , s )
314
+ } )
315
+
316
+
310
317
t . test ( 'html5 meta tag' , async t => {
311
318
const s = '<meta charset="gbk"><div>中文</div>'
312
319
const b = new Body ( convert ( s , 'gbk' ) )
Original file line number Diff line number Diff line change @@ -164,6 +164,12 @@ class TestServer {
164
164
res . end ( convert ( '<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><div>中文</div>' , 'gb2312' ) )
165
165
}
166
166
167
+ if ( p === '/encoding/gb2312-reverse' ) {
168
+ res . statusCode = 200 ;
169
+ res . setHeader ( 'Content-Type' , 'text/html' ) ;
170
+ res . end ( convert ( '<meta content="text/html; charset=gb2312" http-equiv="Content-Type"><div>中文</div>' , 'gb2312' ) ) ;
171
+ }
172
+
167
173
if ( p === '/encoding/shift-jis' ) {
168
174
res . statusCode = 200
169
175
res . setHeader ( 'Content-Type' , 'text/html; charset=Shift-JIS' )
Original file line number Diff line number Diff line change @@ -1767,6 +1767,14 @@ t.test('with optional `encoding`', t => {
1767
1767
} )
1768
1768
} ) )
1769
1769
1770
+ t . test ( 'encoding decode, html4 detect reverse http-equiv' , t =>
1771
+ fetch ( `${ base } encoding/gb2312-reverse` ) . then ( res => {
1772
+ t . equal ( res . status , 200 )
1773
+ return res . textConverted ( ) . then ( result => {
1774
+ t . equal ( result , '<meta content="text/html; charset=gb2312" http-equiv="Content-Type"><div>中文</div>' )
1775
+ } )
1776
+ } ) )
1777
+
1770
1778
t . test ( 'default to utf8 encoding' , t =>
1771
1779
fetch ( `${ base } encoding/utf8` ) . then ( res => {
1772
1780
t . equal ( res . status , 200 )
You can’t perform that action at this time.
0 commit comments