diff --git a/wagtail/admin/static_src/wagtailadmin/js/page-editor.js b/wagtail/admin/static_src/wagtailadmin/js/page-editor.js index dc42dc54b..d2913933f 100644 --- a/wagtail/admin/static_src/wagtailadmin/js/page-editor.js +++ b/wagtail/admin/static_src/wagtailadmin/js/page-editor.js @@ -241,15 +241,21 @@ function cleanForSlug(val, useURLify) { if (useURLify) { // URLify performs extra processing on the string (e.g. removing stopwords) and is more suitable // for creating a slug from the title, rather than sanitising a slug entered manually - return URLify(val, 255, unicodeSlugsEnabled); - } else { - // just do the "replace" - if (unicodeSlugsEnabled) { - return val.replace(/\s/g, '-').replace(/[&\/\\#,+()$~%.'":`@\^!*?<>{}]/g, '').toLowerCase(); - } else { - return val.replace(/\s/g, '-').replace(/[^A-Za-z0-9\-\_]/g, '').toLowerCase(); + let cleaned = URLify(val, 255, unicodeSlugsEnabled); + + // if the result is blank (e.g. because the title consisted entirely of stopwords), + // fall through to the non-URLify method + if (cleaned) { + return cleaned; } } + + // just do the "replace" + if (unicodeSlugsEnabled) { + return val.replace(/\s/g, '-').replace(/[&\/\\#,+()$~%.'":`@\^!*?<>{}]/g, '').toLowerCase(); + } else { + return val.replace(/\s/g, '-').replace(/[^A-Za-z0-9\-\_]/g, '').toLowerCase(); + } } function initSlugAutoPopulate() {