From 6bc8773d5f1ee2004c01e2cd1e011e0cd268fb5a Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 30 Dec 2021 21:06:45 +0100 Subject: [PATCH] handle OPML with empty content, fixes #2495 --- src/services/html_sanitizer.js | 4 ++++ src/services/import/opml.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/html_sanitizer.js b/src/services/html_sanitizer.js index 907001968..2a7e69698 100644 --- a/src/services/html_sanitizer.js +++ b/src/services/html_sanitizer.js @@ -3,6 +3,10 @@ const sanitizeHtml = require('sanitize-html'); // intended mainly as protection against XSS via import // secondarily it (partly) protects against "CSS takeover" function sanitize(dirtyHtml) { + if (!dirtyHtml) { + return dirtyHtml; + } + // avoid H1 per https://github.com/zadam/trilium/issues/1552 // demote H1, and if that conflicts with existing H2, demote that, etc const transformTags = {}; diff --git a/src/services/import/opml.js b/src/services/import/opml.js index 133a7088b..90a8b544d 100644 --- a/src/services/import/opml.js +++ b/src/services/import/opml.js @@ -51,7 +51,7 @@ async function importOpml(taskContext, fileBuffer, parentNote) { throw new Error("Unrecognized OPML version " + opmlVersion); } - content = htmlSanitizer.sanitize(content); + content = htmlSanitizer.sanitize(content || ""); const {note} = noteService.createNewNote({ parentNoteId,