0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 05:02:57 +01:00

Standardize on allowUnicode for slugify util option

- This is the name used in the urlify util
This commit is contained in:
LB Johnston 2024-04-06 15:42:55 +10:00 committed by LB (Ben Johnston)
parent d8e63954d8
commit f0cf73f0d3
3 changed files with 5 additions and 5 deletions

View File

@ -63,9 +63,9 @@ export class SlugController extends Controller<HTMLInputElement> {
event: CustomEvent<{ value: string }> | { detail: { value: string } },
ignoreUpdate = false,
) {
const unicodeSlugsEnabled = this.allowUnicodeValue;
const allowUnicode = this.allowUnicodeValue;
const { value = this.element.value } = event?.detail || {};
const newValue = slugify(value.trim(), { unicodeSlugsEnabled });
const newValue = slugify(value.trim(), { allowUnicode });
if (!ignoreUpdate) {
this.element.value = newValue;

View File

@ -12,7 +12,7 @@ describe('slugify', () => {
});
describe('slugify with unicode slugs enabled', () => {
const options = { unicodeSlugsEnabled: true };
const options = { allowUnicode: true };
it('should return a correct slug', () => {
expect(slugify('The Price is $72.00!', options)).toBe(

View File

@ -4,9 +4,9 @@
*/
export const slugify = (
value: string,
{ unicodeSlugsEnabled = false }: { unicodeSlugsEnabled?: boolean } = {},
{ allowUnicode = false }: { allowUnicode?: boolean } = {},
) =>
unicodeSlugsEnabled
allowUnicode
? value
.replace(/\s+/g, '-')
.replace(/[&/\\#,+()$~%.'":`@^!*?<>{}]/g, '')