Force iframe end tag </iframe> to be wrote (optimized by xml parser)

This commit is contained in:
Gregory Soutade 2022-09-18 17:04:15 +02:00
parent 1b0c92e45a
commit 4ece9e9079
2 changed files with 16 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import hashlib
import gzip
import math
import codecs
import re
from xml.dom import *
from xml.dom.minidom import parse
from xml.parsers.expat import *
@ -64,7 +65,8 @@ class DynastieGenerator:
self.hash_posts = hash_posts
self.hash_posts_content = hash_posts_content
self.user = request and request.user or None
self.iframe_re = re.compile(r'(<iframe.*)/>')
def addReport(self, string, color=''):
if string in self.report: return
if color:
@ -94,8 +96,10 @@ class DynastieGenerator:
writer = StrictUTF8Writer()
node.writexml(writer)
content = writer.getvalue()
content = writer.getvalue().decode('utf-8')
# iframe tag must be like <iframe ... ></iframe>, not optimized <iframe ... />
content = self.iframe_re.sub('\\1></iframe>', content).encode('utf-8')
dst_md5 = hashlib.md5()
dst_md5.update(content)
@ -164,8 +168,8 @@ class DynastieGenerator:
for node in subtree.childNodes:
div.appendChild(node.cloneNode(True))
def createElement(self, dom, name='', content='', subtree=None):
div = dom.createElement('div')
def createElement(self, dom, name='', content='', subtree=None, _type='div'):
div = dom.createElement(_type)
if name:
div.setAttribute('class', name)
if content:

View File

@ -20,6 +20,7 @@
import datetime
import os
import xml
import re
from xml.dom.minidom import parse, parseString
from dynastie.generators.generator import DynastieGenerator, StrictUTF8Writer
from dynastie.generators.index import Index
@ -257,6 +258,7 @@ class Post(Index):
def preview(self, request, src, values):
from dynastie.models import Blog
iframe_re = re.compile(r'(<iframe.*)/>')
self.user = request.user
@ -286,4 +288,8 @@ class Post(Index):
writer = StrictUTF8Writer()
nodes[0].writexml(writer)
return writer.getvalue().decode('utf-8')
content = writer.getvalue().decode('utf-8')
# iframe tag must be like <iframe ... ></iframe>, not optimized <iframe ... />
content = self.iframe_re.sub('\\1></iframe>', content)
return content