mirror of
https://github.com/directus/directus.git
synced 2026-01-29 12:58:00 -05:00
Prevent pasting non slug or db safe characters (#12951)
This commit is contained in:
@@ -156,7 +156,7 @@ function processValue(event: KeyboardEvent) {
|
||||
const value = (event.target as HTMLInputElement).value;
|
||||
|
||||
if (props.slug === true) {
|
||||
const slugSafeCharacters = 'abcdefghijklmnopqrstuvwxyz01234567890-_~ '.split('');
|
||||
const slugSafeCharacters = 'abcdefghijklmnopqrstuvwxyz0123456789-_~ '.split('');
|
||||
|
||||
const isAllowed = slugSafeCharacters.includes(key) || systemKeys.includes(key) || key.startsWith('arrow');
|
||||
|
||||
@@ -170,7 +170,7 @@ function processValue(event: KeyboardEvent) {
|
||||
}
|
||||
|
||||
if (props.dbSafe === true) {
|
||||
const dbSafeCharacters = 'abcdefghijklmnopqrstuvwxyz01234567890_ '.split('');
|
||||
const dbSafeCharacters = 'abcdefghijklmnopqrstuvwxyz0123456789_ '.split('');
|
||||
|
||||
const isAllowed = dbSafeCharacters.includes(key) || systemKeys.includes(key) || key.startsWith('arrow');
|
||||
|
||||
@@ -210,6 +210,9 @@ function emitValue(event: InputEvent) {
|
||||
}
|
||||
} else {
|
||||
if (props.slug === true) {
|
||||
// prevent pasting of non slugSafeCharacters from bypassing the keydown checks
|
||||
value = value.replace(/[^a-zA-Z0-9-_~]/g, '');
|
||||
|
||||
const endsWithSpace = value.endsWith(' ');
|
||||
value = slugify(value, { separator: props.slugSeparator, preserveTrailingDash: true });
|
||||
if (endsWithSpace) value += props.slugSeparator;
|
||||
@@ -217,6 +220,8 @@ function emitValue(event: InputEvent) {
|
||||
|
||||
if (props.dbSafe === true) {
|
||||
value = value.replace(/\s/g, '_');
|
||||
// prevent pasting of non dbSafeCharacters from bypassing the keydown checks
|
||||
value = value.replace(/[^a-zA-Z0-9_]/g, '');
|
||||
// Replace é -> e etc
|
||||
value = value.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user