Code

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#299 closed defect (fixed)

Slugify shouldn't remove hyphens

Reported by: gch@… Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (0)

Change History (1)

comment:1 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.