3
3
*
4
4
* MIT License
5
5
*
6
- * Copyright (c) 2016 - 2019 The Node Fetch Team
6
+ * Copyright (c) 2019 Richie Bendall and 2016 - 2019 The Node Fetch Team
7
7
*
8
8
* Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
* of this software and associated documentation files (the 'Software'), to deal
26
26
27
27
import { decode as convert } from "iconv-lite"
28
28
import getCharSet from "./utils/getCharSet"
29
- import { parse as $ } from "cheerio"
29
+ import { load as $ } from "cheerio"
30
30
import { isURLSearchParams , isBlob , isArrayBuffer } from "./utils/is"
31
31
import { Stream , Writable } from "stream"
32
32
@@ -48,11 +48,13 @@ export function convertBody(buffer: Buffer, headers?: Headers): string {
48
48
const res = buffer . slice ( 0 , 1024 ) . toString ( )
49
49
50
50
// HTML5, HTML4 and XML
51
- if ( ! charset && res ) charset = getCharSet (
52
- $ ( res ) ( "meta[charset]" ) . attr ( "charset" ) || // HTML5
53
- $ ( res ) ( "meta[http-equiv][content]" ) . attr ( "content" ) || // HTML4
54
- $ ( res . replace ( / < \? ( .* ) \? > / im, "<$1>" ) , { xmlMode : true } ) . root ( ) . find ( "xml" ) . attr ( "encoding" ) // XML
55
- )
51
+ if ( ! charset && res ) {
52
+ charset = getCharSet (
53
+ $ ( res ) ( "meta[charset]" ) . attr ( "charset" ) || // HTML5
54
+ $ ( res ) ( "meta[http-equiv][content]" ) . attr ( "content" ) || // HTML4
55
+ $ ( res . replace ( / < \? ( .* ) \? > / im, "<$1>" ) , { xmlMode : true } ) . root ( ) . find ( "xml" ) . attr ( "encoding" ) // XML
56
+ )
57
+ }
56
58
57
59
// Prevent decode issues when sites use incorrect encoding
58
60
// ref: https://hsivonen.fi/encoding-menu/
0 commit comments