From 6a5d192034a0f438551dffb6d2d8df2c00921d16 Mon Sep 17 00:00:00 2001 From: dsuket Date: Mon, 7 Oct 2019 15:58:27 +0900 Subject: [PATCH] fix: Properly parse meta tag when parameters are reversed (#682) --- src/body.js | 6 ++++++ test/server.js | 6 ++++++ test/test.js | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/body.js b/src/body.js index 1b6eab1f8..a9d2e7973 100644 --- a/src/body.js +++ b/src/body.js @@ -306,6 +306,12 @@ function convertBody(buffer, headers) { // html4 if (!res && str) { res = /
中文
', 'gb2312')); } + if (p === '/encoding/gb2312-reverse') { + res.statusCode = 200; + res.setHeader('Content-Type', 'text/html'); + res.end(convert('
中文
', 'gb2312')); + } + if (p === '/encoding/shift-jis') { res.statusCode = 200; res.setHeader('Content-Type', 'text/html; charset=Shift-JIS'); diff --git a/test/test.js b/test/test.js index b8c62dc6d..c5d61c72a 100644 --- a/test/test.js +++ b/test/test.js @@ -2767,6 +2767,16 @@ describe('external encoding', () => { }); }); + it('should support encoding decode, html4 detect reverse http-equiv', function() { + const url = `${base}encoding/gb2312-reverse`; + return fetch(url).then(res => { + expect(res.status).to.equal(200); + return res.textConverted().then(result => { + expect(result).to.equal('
中文
'); + }); + }); + }); + it('should default to utf8 encoding', function() { const url = `${base}encoding/utf8`; return fetch(url).then(res => {