Django

Code

Ticket #299 (closed: fixed)

Opened 3 years ago

Last modified 1 year ago

Slugify shouldn't remove hyphens

Reported by: gch@cs.cmu.edu Assigned to: adrian
Milestone: Component: django.contrib.admin
Version: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Example python session:

>>> from django.core.defaultfilters import slugify
>>> slugify('Django Rocks!', None) 
'django-rocks'
>>> slugify('django-rocks', None)
'djangorocks'

Personally, I think it makes much more sense to not have it remove the hyphens. Basically, you want slugify(slugify(slugify(X))) to equal slugify(X).

The simple fix here is the following diff

Index: defaultfilters.py
===================================================================
--- defaultfilters.py   (revision 463)
+++ defaultfilters.py   (working copy)
@@ -54,7 +54,7 @@
  
 def slugify(value, _):
     "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens"
-    value = re.sub('[^\w\s]', '', value).strip().lower()
+    value = re.sub('[^\w\s-]', '', value).strip().lower()
     return re.sub('\s+', '-', value)
      
 def stringformat(value, arg):

Attachments

Change History

08/10/05 10:40:14 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [464]) Fixed #299 -- Slugify no longer removes hyphens. Thanks, gch@cs.cmu.edu


Add/Change #299 (Slugify shouldn't remove hyphens)




Change Properties
Action