From 9b366ad1c4a7de269f1ce58d3ed7b216b2cc4492 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Thu, 3 Aug 2023 18:38:11 +0800 Subject: [PATCH] EPUB: throw on XML errors --- epub.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/epub.js b/epub.js index 9cd442f..399f7b2 100644 --- a/epub.js +++ b/epub.js @@ -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')