diff options
| author | Sævar Öfjörð Magnússon <saevar@overcast.io> | 2017-10-09 10:40:32 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-10-12 11:50:20 -0400 |
| commit | f90be0a83ef5aa333b19e259faab73ee117d5339 (patch) | |
| tree | 95f03d121e4545b2beab8c200355ac2f6de3da8c | |
| parent | e8649ae36867d8d7233c9ec5e33d9cff7930a006 (diff) | |
Fixed #28688 -- Made admin's URLify.js skip removal of English words if non-ASCII chars are present.
| -rw-r--r-- | django/contrib/admin/static/admin/js/urlify.js | 20 | ||||
| -rw-r--r-- | js_tests/admin/URLify.test.js | 5 |
2 files changed, 18 insertions, 7 deletions
diff --git a/django/contrib/admin/static/admin/js/urlify.js b/django/contrib/admin/static/admin/js/urlify.js index 3504adaaa1..fbce5ba7e8 100644 --- a/django/contrib/admin/static/admin/js/urlify.js +++ b/django/contrib/admin/static/admin/js/urlify.js @@ -155,13 +155,19 @@ if (!allowUnicode) { s = downcode(s); } - var removelist = [ - "a", "an", "as", "at", "before", "but", "by", "for", "from", "is", - "in", "into", "like", "of", "off", "on", "onto", "per", "since", - "than", "the", "this", "that", "to", "up", "via", "with" - ]; - var r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); - s = s.replace(r, ''); + var hasUnicodeChars = /[^\u0000-\u007f]/.test(s); + // Remove English words only if the string contains ASCII (English) + // characters. + if (!hasUnicodeChars) { + var removeList = [ + "a", "an", "as", "at", "before", "but", "by", "for", "from", + "is", "in", "into", "like", "of", "off", "on", "onto", "per", + "since", "than", "the", "this", "that", "to", "up", "via", + "with" + ]; + var r = new RegExp('\\b(' + removeList.join('|') + ')\\b', 'gi'); + s = s.replace(r, ''); + } // if downcode doesn't hit, the char will be stripped here if (allowUnicode) { // Keep Unicode letters including both lowercase and uppercase diff --git a/js_tests/admin/URLify.test.js b/js_tests/admin/URLify.test.js index fafa9af113..cc738bc4ad 100644 --- a/js_tests/admin/URLify.test.js +++ b/js_tests/admin/URLify.test.js @@ -23,3 +23,8 @@ QUnit.test('merge adjacent whitespace', function(assert) { QUnit.test('trim trailing hyphens', function(assert) { assert.strictEqual(URLify('D silent always', 9, true), 'd-silent'); }); + +QUnit.test('do not remove English words if the string contains non-ASCII', function(assert) { + // If removing English words wasn't skipped, the last 'a' would be removed. + assert.strictEqual(URLify('Kaupa-miða', 255, true), 'kaupa-miða'); +}); |
