Skip to content

Commit

Permalink
sanitize display name
Browse files Browse the repository at this point in the history
Signed-off-by: brookewp <brooke.kaminski@automattic.com>
  • Loading branch information
brookewp committed Dec 2, 2024
1 parent c308d5e commit 22eba82
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/data-sources/components/DataSourceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export const DataSourceForm = ( {
};

const onDisplayNameChange = ( displayNameInput: string | undefined ) => {
setDisplayName( displayNameInput ?? '' );
handleOnChange( 'display_name', displayNameInput ?? '' );
const sanitizedDisplayName = displayNameInput
?.toString()
.trim()
.replace( /[^a-zA-Z0-9-_ ]/g, '' );
setDisplayName( sanitizedDisplayName ?? '' );
handleOnChange( 'display_name', sanitizedDisplayName ?? '' );
};

return (
Expand Down

0 comments on commit 22eba82

Please sign in to comment.