html-get 2.30.1 → 2.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/util.js +16 -1
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "html-get",
3
3
  "description": "Get the HTML from any website, fine-tuned for correction & speed",
4
4
  "homepage": "https://nicedoc.com/microlinkhq/html-get",
5
- "version": "2.30.1",
5
+ "version": "2.30.2",
6
6
  "types": "index.d.ts",
7
7
  "main": "src/index.js",
8
8
  "bin": {
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "@kikobeats/got": "~11.8.8",
49
49
  "@kikobeats/time-span": "~1.0.13",
50
- "@metascraper/helpers": "~5.58.4",
50
+ "@metascraper/helpers": "~5.59.3",
51
51
  "cheerio": "~1.2.0",
52
52
  "content-type": "~3.1.0",
53
53
  "css-url-regex": "~4.0.0",
package/src/util.js CHANGED
@@ -12,9 +12,24 @@ const UNKNOWN_CONTENT_TYPE = { type: undefined, parameters: {} }
12
12
 
13
13
  const SEPARATOR = /,|\r?\n/
14
14
 
15
+ const BYTE_ORDER_MARKS = [
16
+ '\ufeff',
17
+ '\u00ef\u00bb\u00bf',
18
+ '\u0000\u0000\u00fe\u00ff',
19
+ '\u00ff\u00fe\u0000\u0000',
20
+ '\u00fe\u00ff',
21
+ '\u00ff\u00fe'
22
+ ]
23
+
24
+ const LEADING_WHITESPACE_AND_BYTE_ORDER_MARKS = new RegExp(
25
+ `^(?:[\\t ]|${BYTE_ORDER_MARKS.join('|')})+`
26
+ )
27
+
15
28
  const parseContentType = contentType => {
16
29
  if (typeof contentType !== 'string') return UNKNOWN_CONTENT_TYPE
17
- const parsed = parse(contentType.split(SEPARATOR)[0])
30
+ const parsed = parse(
31
+ contentType.replace(LEADING_WHITESPACE_AND_BYTE_ORDER_MARKS, '').split(SEPARATOR)[0]
32
+ )
18
33
  return parsed.type?.includes('/') ? parsed : UNKNOWN_CONTENT_TYPE
19
34
  }
20
35