fix: Fix removetags (#4226)

I don't think this ever worked.
This commit is contained in:
Lars Eggert 2022-07-18 17:39:11 +03:00 committed by GitHub
parent dde5ed4650
commit 0038151bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -34,7 +34,7 @@ def unescape(text):
def remove_tags(html, tags): def remove_tags(html, tags):
"""Returns the given HTML sanitized, and with the given tags removed.""" """Returns the given HTML sanitized, and with the given tags removed."""
allowed = set(acceptable_tags) - set([ t.lower() for t in tags ]) allowed = set(acceptable_tags) - set([ t.lower() for t in tags ])
return bleach.clean(html, tags=allowed) return bleach.clean(html, tags=allowed, strip=True)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Html fragment cleaning # Html fragment cleaning

View file

@ -1,6 +1,7 @@
# Copyright The IETF Trust 2017-2020, All Rights Reserved # Copyright The IETF Trust 2017-2020, All Rights Reserved
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re
from django.template.library import Library from django.template.library import Library
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
@ -9,9 +10,9 @@ from ietf.utils.html import remove_tags
register = Library() register = Library()
@register.filter(is_safe=True) @register.filter(is_safe=True)
@stringfilter @stringfilter
def removetags(value, tags): def removetags(value, tags):
"""Removes a space separated list of [X]HTML tags from the output.""" """Removes a comma-separated list of [X]HTML tags from the output."""
return remove_tags(value, tags) return remove_tags(value, re.split(r"\s*,\s*", tags))