Properly remove all attributes when unserializing HTML from the existin

HTML, HEAD and BODY tags
This commit is contained in:
Kovid Goyal 2019-08-17 14:46:18 +05:30
parent dc887b9780
commit 782c088bb9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 1 deletions

View File

@ -59,12 +59,21 @@ def build_rule(selector, **kw):
ans.push('}')
return ans.join('\n') + '\n'
def clear():
for v'var i = 0; i < arguments.length; i++':
node = arguments[i]
while node.firstChild:
node.removeChild(node.firstChild)
def remove_all_attributes():
for v'var i = 0; i < arguments.length; i++':
node = arguments[i]
while node.attributes.length > 0:
node.removeAttribute(node.attributes[0].name)
def create_keyframes(animation_name, *frames):
ans = v'[]'
for prefix in '-webkit-', '-moz-', '-o-', '':

View File

@ -5,7 +5,7 @@ from __python__ import hash_literals
from elementmaker import E
from encodings import base64decode, utf8_decode
from dom import clear
from dom import clear, remove_all_attributes
from read_book.globals import ui_operations
JSON_XHTML_MIMETYPE = 'application/calibre+xhtml+json'
@ -228,9 +228,11 @@ def unserialize_html(serialized_data, proceed, postprocess_dom):
tree = serialized_data.tree
ns_map = serialized_data.ns_map
html = tag_map[0]
remove_all_attributes(document.documentElement)
apply_attributes(html, document.documentElement, ns_map)
head, body = tree[1], tree[2] # noqa: unused-local
clear(document.head, document.body)
remove_all_attributes(document.head, document.body)
# Default stylesheet
document.head.appendChild(E.style(type='text/css', 'html {{ font-family: {} }}'.format(window.default_font_family or "sans-serif")))
resource_urls = {}