Fixed #20221 -- Allowed some functions that use mark_safe() to result in SafeText.

Thanks Baptiste Mispelon for the report.
This commit is contained in:
Jon Dufresne 2014-10-15 18:03:40 -07:00 committed by Tim Graham
parent 4fe6824ffd
commit 54e695331b
3 changed files with 21 additions and 5 deletions

View file

@ -12,7 +12,7 @@ from django.utils.functional import allow_lazy, SimpleLazyObject
from django.utils import six
from django.utils.six.moves import html_entities
from django.utils.translation import ugettext_lazy, ugettext as _, pgettext
from django.utils.safestring import mark_safe
from django.utils.safestring import SafeText, mark_safe
if six.PY2:
# Import force_unicode even though this module doesn't use it, because some
@ -442,10 +442,11 @@ def slugify(value):
underscores) and converts spaces to hyphens. Also strips leading and
trailing whitespace.
"""
value = force_text(value)
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub('[^\w\s-]', '', value).strip().lower()
return mark_safe(re.sub('[-\s]+', '-', value))
slugify = allow_lazy(slugify, six.text_type)
slugify = allow_lazy(slugify, six.text_type, SafeText)
def camel_case_to_spaces(value):