Code

Ticket #2276: defaultfilters.py.3.diff

File defaultfilters.py.3.diff, 740 bytes (added by nkeric, 8 years ago)

output string should be utf-8 encoded as input string

Line 
1Index: django/template/defaultfilters.py
2===================================================================
3--- django/template/defaultfilters.py   (revision 3254)
4+++ django/template/defaultfilters.py   (working copy)
5@@ -65,8 +65,11 @@
6 
7 def slugify(value):
8     "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens"
9-    value = re.sub('[^\w\s-]', '', value).strip().lower()
10-    return re.sub('[-\s]+', '-', value)
11+    decoded_value = unicode(value, 'utf-8')
12+    p = re.compile('[^\w\s-]', re.UNICODE)
13+    decoded_value = re.sub(p, '', decoded_value).strip().lower()
14+    decoded_value = re.sub('[-\s]+', '-', decoded_value)
15+    return decoded_value.encode('utf-8')
16 
17 def stringformat(value, arg):
18     """