Skip to content

Commit 7c4f05f

Browse files
monotoneetimgraham
authored andcommitted
Fixed #28295 -- Made admin's URLify.js trim trailing hyphens.
1 parent 68812ba commit 7c4f05f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

django/contrib/admin/static/admin/js/urlify.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@
172172
}
173173
s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
174174
s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens
175-
s = s.toLowerCase(); // convert to lowercase
176-
return s.substring(0, num_chars); // trim to first num_chars chars
175+
s = s.substring(0, num_chars); // trim to first num_chars chars
176+
s = s.replace(/-+$/g, ''); // trim any trailing hyphens
177+
return s.toLowerCase(); // convert to lowercase
177178
}
178179
window.URLify = URLify;
179180
})();

js_tests/admin/URLify.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ QUnit.test('strip non-URL characters', function(assert) {
1919
QUnit.test('merge adjacent whitespace', function(assert) {
2020
assert.strictEqual(URLify('D silent', 8, true), 'd-silent');
2121
});
22+
23+
QUnit.test('trim trailing hyphens', function(assert) {
24+
assert.strictEqual(URLify('D silent always', 9, true), 'd-silent');
25+
});

0 commit comments

Comments
 (0)