mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
FB2: fix encoding on Firefox
This commit is contained in:
@@ -146,9 +146,12 @@ const parseXML = async blob => {
|
|||||||
const str = new TextDecoder('utf-8').decode(buffer)
|
const str = new TextDecoder('utf-8').decode(buffer)
|
||||||
const parser = new DOMParser()
|
const parser = new DOMParser()
|
||||||
const doc = parser.parseFromString(str, MIME.XML)
|
const doc = parser.parseFromString(str, MIME.XML)
|
||||||
// FIXME: `Document.xmlEncoding` is deprecated
|
const encoding = doc.xmlEncoding
|
||||||
if (doc.xmlEncoding && doc.xmlEncoding !== 'utf-8') {
|
// `Document.xmlEncoding` is deprecated, and already removed in Firefox
|
||||||
const str = new TextDecoder(doc.xmlEncoding).decode(buffer)
|
// so parse the XML declaration manually
|
||||||
|
|| str.match(/^<\?xml\s+version\s*=\s*["']1.\d+"\s+encoding\s*=\s*["']([A-Za-z0-9._-]*)["']/)?.[1]
|
||||||
|
if (encoding && encoding.toLowerCase() !== 'utf-8') {
|
||||||
|
const str = new TextDecoder(encoding).decode(buffer)
|
||||||
return parser.parseFromString(str, MIME.XML)
|
return parser.parseFromString(str, MIME.XML)
|
||||||
}
|
}
|
||||||
return doc
|
return doc
|
||||||
|
|||||||
Reference in New Issue
Block a user