File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,12 @@ function convertBody(buffer, headers) {
306
306
// html4
307
307
if ( ! res && str ) {
308
308
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 ) ;
309
+ if ( ! res ) {
310
+ 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 ) ;
311
+ if ( res ) {
312
+ res . pop ( ) ; // drop last quote
313
+ }
314
+ }
309
315
310
316
if ( res ) {
311
317
res = / c h a r s e t = ( .* ) / i. exec ( res . pop ( ) ) ;
Original file line number Diff line number Diff line change @@ -181,6 +181,12 @@ export default class TestServer {
181
181
res . end ( convert ( '<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><div>中文</div>' , 'gb2312' ) ) ;
182
182
}
183
183
184
+ if ( p === '/encoding/gb2312-reverse' ) {
185
+ res . statusCode = 200 ;
186
+ res . setHeader ( 'Content-Type' , 'text/html' ) ;
187
+ res . end ( convert ( '<meta content="text/html; charset=gb2312" http-equiv="Content-Type"><div>中文</div>' , 'gb2312' ) ) ;
188
+ }
189
+
184
190
if ( p === '/encoding/shift-jis' ) {
185
191
res . statusCode = 200 ;
186
192
res . setHeader ( 'Content-Type' , 'text/html; charset=Shift-JIS' ) ;
Original file line number Diff line number Diff line change @@ -2767,6 +2767,16 @@ describe('external encoding', () => {
2767
2767
} ) ;
2768
2768
} ) ;
2769
2769
2770
+ it ( 'should support encoding decode, html4 detect reverse http-equiv' , function ( ) {
2771
+ const url = `${ base } encoding/gb2312-reverse` ;
2772
+ return fetch ( url ) . then ( res => {
2773
+ expect ( res . status ) . to . equal ( 200 ) ;
2774
+ return res . textConverted ( ) . then ( result => {
2775
+ expect ( result ) . to . equal ( '<meta content="text/html; charset=gb2312" http-equiv="Content-Type"><div>中文</div>' ) ;
2776
+ } ) ;
2777
+ } ) ;
2778
+ } ) ;
2779
+
2770
2780
it ( 'should default to utf8 encoding' , function ( ) {
2771
2781
const url = `${ base } encoding/utf8` ;
2772
2782
return fetch ( url ) . then ( res => {
You can’t perform that action at this time.
0 commit comments