trivial: update to use html.unescape (#48794)

This commit is contained in:
Frédéric Péters 2020-11-24 14:22:43 +01:00
parent 3f3bfeda73
commit 901b2006ae
3 changed files with 6 additions and 7 deletions

View File

@ -18,6 +18,7 @@
import copy
import datetime
import html
import os
import time
import random
@ -34,7 +35,6 @@ from django.utils import six
from django.utils.encoding import force_bytes, force_text, smart_text
from django.utils.formats import date_format as django_date_format
from django.utils.html import urlize
from django.utils.six.moves.html_parser import HTMLParser
from .qommon import _, N_, force_str
from .qommon import evalutils
@ -213,7 +213,7 @@ class Field(object):
@property
def unhtmled_label(self):
return force_str(HTMLParser().unescape(force_text(
return force_str(html.unescape(force_text(
re.sub('<.*?>', ' ', self.label))).strip())
def get_admin_attributes(self):

View File

@ -18,6 +18,7 @@ import base64
import collections
import copy
import fnmatch
import html
import mimetypes
import os
import re
@ -64,7 +65,6 @@ from quixote.util import randbytes
from django.utils.encoding import force_bytes, force_text
from django.utils import six
from django.utils.six.moves.html_parser import HTMLParser
from django.conf import settings
from django.utils.safestring import mark_safe
@ -1718,10 +1718,9 @@ class WysiwygTextWidget(TextWidget):
if self.value.endswith('<br />'):
self.value = self.value[:-6]
# unescape Django template tags
parser = HTMLParser()
charset = get_publisher().site_charset
def unquote_django(matchobj):
return force_str(parser.unescape(force_text(matchobj.group(0), charset)))
return force_str(html.unescape(force_text(matchobj.group(0), charset)))
self.value = re.sub('{[{%](.*?)[%}]}', unquote_django, self.value)
if self.validation_function:
try:

View File

@ -17,6 +17,7 @@
import datetime
import decimal
import calendar
import html
import re
import os
import time
@ -40,7 +41,6 @@ from django.utils import six
from django.utils.encoding import force_text
from django.utils.html import strip_tags
from django.template import TemplateSyntaxError, VariableDoesNotExist
from django.utils.six.moves.html_parser import HTMLParser
from django.utils.six.moves.urllib.parse import quote, urlencode
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.text import Truncator
@ -680,7 +680,7 @@ def normalize_geolocation(lat_lon):
def html2text(text):
if isinstance(text, (htmltext, str)):
text = force_text(str(text), get_publisher().site_charset)
return site_encode(HTMLParser().unescape(strip_tags(text)))
return site_encode(html.unescape(strip_tags(text)))
def validate_luhn(string_value, length=None):