Tweaks to handle text types better and make set operation clearer.

- Legacy-Id: 14745
This commit is contained in:
Henrik Levkowetz 2018-03-07 21:10:47 +00:00
parent 802f201d81
commit 2fd344f810
2 changed files with 5 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import os
from django.conf import settings
from django.contrib import messages
from django.utils.encoding import smart_text
import debug # pyflakes:ignore
@ -36,8 +37,9 @@ def handle_upload_file(file,filename,meeting,subdir, request=None):
destination = open(os.path.join(path,filename), 'wb+')
if extension in settings.MEETING_VALID_MIME_TYPE_EXTENSIONS['text/html']:
file.open()
text = file.read().decode('utf-8')
# Whole file sanitization; add back '<html>' (sanitize will remove it)
text = smart_text(file.read())
# Whole file sanitization; add back what's missing from a complete
# document (sanitize will remove these).
clean = u"""<!DOCTYPE html>
<html lang="en">
<head><title>%s</title></head>

View file

@ -26,7 +26,7 @@ class StripFilter(Filter):
for token in Filter.__iter__(self):
if token["type"] in ["EmptyTag", "StartTag"]:
open_tags.append(token["name"])
if not set(strip_completely) & set(open_tags):
if not (set(open_tags) & set(strip_completely)):
yield token
if token["type"] in ["EmptyTag", "EndTag"]:
open_tags.pop()