File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -306,6 +306,12 @@ function convertBody(buffer, headers) {
306306 // html4
307307 if ( ! res && str ) {
308308 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+ }
309315
310316 if ( res ) {
311317 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 {
181181 res . end ( convert ( '<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><div>中文</div>' , 'gb2312' ) ) ;
182182 }
183183
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+
184190 if ( p === '/encoding/shift-jis' ) {
185191 res . statusCode = 200 ;
186192 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', () => {
27672767 } ) ;
27682768 } ) ;
27692769
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+
27702780 it ( 'should default to utf8 encoding' , function ( ) {
27712781 const url = `${ base } encoding/utf8` ;
27722782 return fetch ( url ) . then ( res => {
You can’t perform that action at this time.
0 commit comments