diff --git a/CHANGELOG.txt b/CHANGELOG.txt index aa8428a744..ffa5c52722 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -58,6 +58,7 @@ Changelog * Fix: Retain query parameters when switching between locales in the page chooser (Abdelrahman Hamada, Sage Abdullah) * Fix: Add `w-kbd-scope-value` with support for `global` so that specific keyboard shortcuts (e.g. ctrl+s/cmd+s) trigger consistently even when focused on fields (Neeraj Yetheendran) * Fix: Improve exception handling when generating image renditions concurrently (Andy Babic) + * Fix: Respect `WAGTAIL_ALLOW_UNICODE_SLUGS` setting when auto-generating slugs (LB (Ben) Johnston) * Docs: Add contributing development documentation on how to work with a fork of Wagtail (Nix Asteri, Dan Braghis) * Docs: Make sure the settings panel is listed in tabbed interface examples (Tibor Leupold) * Docs: Update content and page names to their US spelling instead of UK spelling (Victoria Poromon) diff --git a/client/src/controllers/SlugController.test.js b/client/src/controllers/SlugController.test.js index 38a71d07da..6fad12efec 100644 --- a/client/src/controllers/SlugController.test.js +++ b/client/src/controllers/SlugController.test.js @@ -45,7 +45,7 @@ describe('SlugController', () => { expect(slugInput.value).toEqual('visiter-toulouse-en-t-2025'); }); - it('should now allow unicode characters by default', () => { + it('should allow unicode characters when allow-unicode-value is set to truthy', () => { const slugInput = document.querySelector('#id_slug'); slugInput.setAttribute('data-w-slug-allow-unicode-value', 'true'); @@ -267,7 +267,7 @@ describe('urlify behaviour', () => { expect(slugInput.value).toBe('urlify-testing-on-edit-page'); }); - it('should transform input with special characters to their ASCII equivalent', () => { + it('should transform input with special (unicode) characters to their ASCII equivalent by default', () => { const slugInput = document.getElementById('id_slug'); slugInput.value = 'Some Title with éçà Spaces'; @@ -280,6 +280,21 @@ describe('urlify behaviour', () => { expect(slugInput.value).toBe('some-title-with-eca-spaces'); }); + it('should transform input with special (unicode) characters to keep unicode values if allow unicode value is truthy', () => { + const value = 'Dê-me fatias de pizza de manhã --ou-- à noite'; + + const slugInput = document.getElementById('id_slug'); + slugInput.setAttribute('data-w-slug-allow-unicode-value', 'true'); + + slugInput.value = value; + + const event = new CustomEvent('custom:event', { detail: { value } }); + + document.getElementById('id_slug').dispatchEvent(event); + + expect(slugInput.value).toBe('dê-me-fatias-de-pizza-de-manhã-ou-à-noite'); + }); + it('should return an empty string when input contains only special characters', () => { const slugInput = document.getElementById('id_slug'); slugInput.value = '$$!@#$%^&*'; diff --git a/client/src/controllers/SlugController.ts b/client/src/controllers/SlugController.ts index f3b86fc54f..3d1eccac18 100644 --- a/client/src/controllers/SlugController.ts +++ b/client/src/controllers/SlugController.ts @@ -89,12 +89,12 @@ export class SlugController extends Controller { event: CustomEvent<{ value: string }> | { detail: { value: string } }, ignoreUpdate = false, ) { + const allowUnicode = this.allowUnicodeValue; const { value = this.element.value } = event?.detail || {}; - const trimmedValue = value.trim(); const newValue = - urlify(trimmedValue) || + urlify(trimmedValue, { allowUnicode }) || this.slugify({ detail: { value: trimmedValue } }, true); if (!ignoreUpdate) { diff --git a/docs/releases/6.1.md b/docs/releases/6.1.md index 010690d6a6..9a4b8e8e7c 100644 --- a/docs/releases/6.1.md +++ b/docs/releases/6.1.md @@ -87,6 +87,7 @@ This feature was developed by Ben Enright and Thibaud Colas. * Retain query parameters when switching between locales in the page chooser (Abdelrahman Hamada, Sage Abdullah) * Add `w-kbd-scope-value` with support for `global` so that specific keyboard shortcuts (e.g. ctrl+s/cmd+s) trigger consistently even when focused on fields (Neeraj Yetheendran) * Improve exception handling when generating image renditions concurrently (Andy Babic) + * Respect `WAGTAIL_ALLOW_UNICODE_SLUGS` setting when auto-generating slugs (LB (Ben) Johnston) ### Documentation