mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-01-07 14:22:38 +01:00
fix non utf-8 encoding
This commit is contained in:
parent
e153ec23dc
commit
798c26bed9
@ -27,6 +27,7 @@ const rssParser = new Parser({
|
||||
}
|
||||
})
|
||||
|
||||
const CHARSET_RE = /charset=([^()<>@,;:\"/[\]?.=\s]*)/i
|
||||
export async function parseRSS(url: string) {
|
||||
let result: Response
|
||||
try {
|
||||
@ -36,7 +37,11 @@ export async function parseRSS(url: string) {
|
||||
}
|
||||
if (result && result.ok) {
|
||||
try {
|
||||
return await rssParser.parseString(await result.text())
|
||||
const buffer = await result.arrayBuffer()
|
||||
const ctype = result.headers.has("content-type") && result.headers.get("content-type")
|
||||
const charset = (ctype && CHARSET_RE.test(ctype)) ? CHARSET_RE.exec(ctype)[1] : "utf-8"
|
||||
const decoder = new TextDecoder(charset)
|
||||
return await rssParser.parseString(decoder.decode(buffer))
|
||||
} catch {
|
||||
throw new Error(intl.get("log.parseError"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user