From 0382ecfe020b4c51b4c01e4e9a21892771e66941 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 26 May 2020 22:56:41 +0100 Subject: Fixed #28694 -- Made django.utils.text.slugify() strip dashes and underscores. --- django/utils/text.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'django/utils') diff --git a/django/utils/text.py b/django/utils/text.py index cb39110b83..4d77ce7f41 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -396,15 +396,15 @@ def slugify(value, allow_unicode=False): Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren't alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and - trailing whitespace. + trailing whitespace, dashes, and underscores. """ value = str(value) if allow_unicode: value = unicodedata.normalize('NFKC', value) else: value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') - value = re.sub(r'[^\w\s-]', '', value.lower()).strip() - return re.sub(r'[-\s]+', '-', value) + value = re.sub(r'[^\w\s-]', '', value.lower()) + return re.sub(r'[-\s]+', '-', value).strip('-_') def camel_case_to_spaces(value): -- cgit v1.3