From 9f02e703171d510db40d70af3bb6dd99496d5a85 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 29 Oct 2019 18:24:39 +0530 Subject: [PATCH] Ensure root tag is in correct namespace --- src/calibre/srv/render_book.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 257077ad24..ff767478f5 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -755,11 +755,14 @@ def ensure_body(root): def html_as_json(root): + ns, name = split_name(root.tag) + if ns not in (None, XHTML_NS): + raise ValueError('HTML tag must be in empty or XHTML namespace') + ensure_body(root) try: serialize = plugins['html_as_json'][0].serialize except KeyError: return as_bytes(json.dumps(html_as_dict(root), ensure_ascii=False, separators=(',', ':'))) - ensure_body(root) for child in tuple(root.iterchildren('*')): if child.tag.partition('}')[-1] not in ('head', 'body'): root.remove(child) @@ -768,7 +771,6 @@ def html_as_json(root): def html_as_dict(root): - ensure_body(root) for child in tuple(root.iterchildren('*')): if child.tag.partition('}')[-1] not in ('head', 'body'): root.remove(child)