1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Fixed #28295 -- Made admin's URLify.js trim trailing hyphens.

This commit is contained in:
monotonee 2017-06-13 14:41:21 -04:00 committed by Tim Graham
parent 68812ba868
commit 7c4f05fae2
2 changed files with 7 additions and 2 deletions

View File

@ -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;
})();

View File

@ -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');
});