From 51f6a9442c21d6288ccca9b8d9ebaf2f6ecd5b9d Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 15 May 2006 04:20:04 +0000 Subject: [PATCH] Fixed #1849 -- Slugifying now collapses consecutive hyphens to a single hyphen. Thanks, Tom Insam git-svn-id: http://code.djangoproject.com/svn/django/trunk@2905 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/contrib/admin/media/js/urlify.js | 4 ++-- django/template/defaultfilters.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 4e44004768..5864c7107f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -106,6 +106,7 @@ answer newbie questions, and generally made Django that much better: Swaroop C H Aaron Swartz Tom Tobin + Tom Insam Joe Topjian Malcolm Tredinnick Amit Upadhyay diff --git a/django/contrib/admin/media/js/urlify.js b/django/contrib/admin/media/js/urlify.js index 8b8dbfa59e..90d11c435a 100644 --- a/django/contrib/admin/media/js/urlify.js +++ b/django/contrib/admin/media/js/urlify.js @@ -9,7 +9,7 @@ function URLify(s, num_chars) { s = s.replace(r, ''); s = s.replace(/[^-A-Z0-9\s]/gi, ''); // remove unneeded chars s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces - s = s.replace(/\s+/g, '-'); // convert spaces to hyphens + s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens s = s.toLowerCase(); // convert to lowercase return s.substring(0, num_chars);// trim to first num_chars chars -} \ No newline at end of file +} diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index fa4975e643..7820e72342 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -66,7 +66,7 @@ def make_list(value): def slugify(value): "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens" value = re.sub('[^\w\s-]', '', value).strip().lower() - return re.sub('\s+', '-', value) + return re.sub('[-\s]+', '-', value) def stringformat(value, arg): """