From fc69f3b8f3a538e5b8d89c197081a28f6e501b4f Mon Sep 17 00:00:00 2001 From: Sylvain Pasche Date: Sun, 18 Sep 2022 18:14:25 +0200 Subject: [PATCH] let import continue when malformed URLs are encountered In case of malformed URLs in imported HTML, keep original URL instead of having the import get stuck. --- src/services/import/zip.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 09639c3b1..e182126c1 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -292,7 +292,12 @@ async function importZip(taskContext, fileBuffer, importRootNote) { content = content.replace(/<\/body>.*<\/html>/gis, ""); content = content.replace(/src="([^"]*)"/g, (match, url) => { - url = decodeURIComponent(url); + try { + url = decodeURIComponent(url); + } catch (e) { + log.error(`Cannot parse image URL '${url}', keeping original (${e}).`); + return `src="${url}"`; + } if (isUrlAbsolute(url) || url.startsWith("/")) { return match; @@ -304,7 +309,12 @@ async function importZip(taskContext, fileBuffer, importRootNote) { }); content = content.replace(/href="([^"]*)"/g, (match, url) => { - url = decodeURIComponent(url); + try { + url = decodeURIComponent(url); + } catch (e) { + log.error(`Cannot parse link URL '${url}', keeping original (${e}).`); + return `href="${url}"`; + } if (isUrlAbsolute(url)) { return match;