Skip to content

Commit

Permalink
EPUB: throw on XML errors
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfactotum committed Aug 3, 2023
1 parent 739a00f commit 9b366ad
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,14 @@ export class EPUB {
this.getSize = getSize
this.#encryption = new Encryption(deobfuscators(sha1))
}
#parseXML(str) {
return str ? this.parser.parseFromString(str, MIME.XML) : null
}
async #loadXML(uri) {
return this.#parseXML(await this.loadText(uri))
const str = await this.loadText(uri)
if (!str) return null
const doc = this.parser.parseFromString(str, MIME.XML)
if (doc.querySelector('parsererror'))
throw new Error(`XML parsing error: ${uri}
${doc.querySelector('parsererror').innerText}`)
return doc
}
async init() {
const $container = await this.#loadXML('META-INF/container.xml')
Expand Down

0 comments on commit 9b366ad

Please sign in to comment.