diff options
| author | David Smith <smithdc@gmail.com> | 2020-05-26 22:56:41 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-05-29 06:47:51 +0200 |
| commit | 0382ecfe020b4c51b4c01e4e9a21892771e66941 (patch) | |
| tree | dd02f774b9f3d5df56053516b019d77852ccb491 /django/utils | |
| parent | 3111b434e76e68a0c1bdb0e3f0c599b249b173ad (diff) | |
Fixed #28694 -- Made django.utils.text.slugify() strip dashes and underscores.
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/text.py | 6 |
1 files changed, 3 insertions, 3 deletions
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): |
