Skip to content

Commit

Permalink
fix(frontend): fix property name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
alice.juan committed Feb 8, 2024
1 parent 23f2b0c commit 4609c25
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ const ListAllEntryProperties = ({ nodeObject, setNodeObject }) => {
const validatePropertyName = (propertyName: string): boolean => {
// Every property name should be in the form property_name:lang_code
if (propertyName) {
const [, langCode] = propertyName.split(":");
const words = propertyName.split(":");
const langCode = words[words.length - 1];
if (!LanguageCodes.includes(langCode as LanguageCode)) {
return false;
}
// Property name should not include special caracters
const pattern = /^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$/;
if (!pattern.test(propertyName)) {
return false;
for (const word of words) {
const pattern = /^[a-zA-Z0-9_]+$/;
if (!pattern.test(word)) {
return false;
}
}
return true;
}
Expand Down

0 comments on commit 4609c25

Please sign in to comment.