From 7c4f05fae2ae12d698dc28421f5d4659162f928a Mon Sep 17 00:00:00 2001 From: monotonee Date: Tue, 13 Jun 2017 14:41:21 -0400 Subject: [PATCH] Fixed #28295 -- Made admin's URLify.js trim trailing hyphens. --- django/contrib/admin/static/admin/js/urlify.js | 5 +++-- js_tests/admin/URLify.test.js | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/static/admin/js/urlify.js b/django/contrib/admin/static/admin/js/urlify.js index 9dcbc82d13..3504adaaa1 100644 --- a/django/contrib/admin/static/admin/js/urlify.js +++ b/django/contrib/admin/static/admin/js/urlify.js @@ -172,8 +172,9 @@ } s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 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 + s = s.substring(0, num_chars); // trim to first num_chars chars + s = s.replace(/-+$/g, ''); // trim any trailing hyphens + return s.toLowerCase(); // convert to lowercase } window.URLify = URLify; })(); diff --git a/js_tests/admin/URLify.test.js b/js_tests/admin/URLify.test.js index b1d7d1f301..fafa9af113 100644 --- a/js_tests/admin/URLify.test.js +++ b/js_tests/admin/URLify.test.js @@ -19,3 +19,7 @@ QUnit.test('strip non-URL characters', function(assert) { QUnit.test('merge adjacent whitespace', function(assert) { assert.strictEqual(URLify('D silent', 8, true), 'd-silent'); }); + +QUnit.test('trim trailing hyphens', function(assert) { + assert.strictEqual(URLify('D silent always', 9, true), 'd-silent'); +});