Skip to content

Commit 52c7b5d

Browse files
committed
Fix HTML4 charset detection
Fixes #151 Signed-off-by: Richie Bendall <[email protected]>
1 parent 05433e5 commit 52c7b5d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

source/utils/get-charset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function getCharset(content: Buffer, headers?: Headers) {
2828

2929
charset = parseContentType(
3030
$('meta[charset]').attr('charset') // HTML5
31-
|| $('meta[http-equiv][content]').attr('content') // HTML4
31+
|| $('meta[http-equiv=Content-Type][content]').attr('content') // HTML4
3232
|| load(data.replace(/<\?(.*)\?>/im, '<$1>'), {xmlMode: true}).root().find('xml').attr('encoding'), // XML
3333
);
3434

test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ test('should support encoding decode, html4 detect', t => {
2626
t.is(convertBody(iconv.encode(text, 'gb2312'), new Headers({'Content-Type': 'text/html'})), text);
2727
});
2828

29+
test('should select the correct meta tag, html4 detect', t => {
30+
const text = '<meta http-equiv="Language" content="de"/><meta http-equiv="Content-Language" content="de"/><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>';
31+
t.is(convertBody(iconv.encode(text, 'iso-8859-1'), new Headers({'Content-Type': 'text/html'})), text);
32+
});
33+
2934
test('should support uncommon content-type order, end with qs', t => {
3035
const text = '中文';
3136
t.is(convertBody(iconv.encode(text, 'gbk'), new Headers({'Content-Type': 'text/plain; charset=gbk; qs=1'})), text);

0 commit comments

Comments
 (0)