Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions web/lib/react/components/organization/user/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ const generalSchema = yup
.required('Name is required')
.min(2, 'Name must be at least 2 characters')
.matches(
/^[a-zA-Z\s'-]+$/,
'Name can only contain letters, spaces, hyphens, and apostrophes'
/^[\p{L}\s.'-]+$/u,
'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
)
.matches(/^\p{L}/u, 'Name must start with a letter')
.matches(
/^\p{L}[\p{L}\s.'-]*\p{L}$|^\p{L}$/u,
'Name must end with a letter'
)
.matches(/^(?!.*\s\s).*$/, 'Name cannot have consecutive spaces')
.matches(/^(?!.*\s[^\p{L}]).*$/u, 'Spaces must be followed by a letter')
Comment on lines +28 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

\s permits tabs, newlines, and other whitespace — use a literal space instead.

\s matches \t, \n, \r, \f, \v, and (with the u flag) additional Unicode whitespace characters. A value like "John\tDoe" would pass every check in this chain. The error messages and PR description consistently refer to "spaces," so the intent is clearly to allow only the ASCII space character.

🔧 Proposed fix — replace \s with literal space in all four regexes
      .matches(
-        /^[\p{L}\s.'-]+$/u,
+        /^[\p{L} .'-]+$/u,
         'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
       )
       .matches(/^\p{L}/u, 'Name must start with a letter')
       .matches(
-        /^\p{L}[\p{L}\s.'-]*\p{L}$|^\p{L}$/u,
+        /^\p{L}[\p{L} .'-]*\p{L}$|^\p{L}$/u,
         'Name must end with a letter'
       )
-      .matches(/^(?!.*\s\s).*$/, 'Name cannot have consecutive spaces')
-      .matches(/^(?!.*\s[^\p{L}]).*$/u, 'Spaces must be followed by a letter')
+      .matches(/^(?!.*  ).*$/, 'Name cannot have consecutive spaces')
+      .matches(/^(?!.* [^\p{L}]).*$/u, 'Spaces must be followed by a letter')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/^[\p{L}\s.'-]+$/u,
'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
)
.matches(/^\p{L}/u, 'Name must start with a letter')
.matches(
/^\p{L}[\p{L}\s.'-]*\p{L}$|^\p{L}$/u,
'Name must end with a letter'
)
.matches(/^(?!.*\s\s).*$/, 'Name cannot have consecutive spaces')
.matches(/^(?!.*\s[^\p{L}]).*$/u, 'Spaces must be followed by a letter')
/^[\p{L} .'-]+$/u,
'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
)
.matches(/^\p{L}/u, 'Name must start with a letter')
.matches(
/^\p{L}[\p{L} .'-]*\p{L}$|^\p{L}$/u,
'Name must end with a letter'
)
.matches(/^(?!.* ).*$/, 'Name cannot have consecutive spaces')
.matches(/^(?!.* [^\p{L}]).*$/u, 'Spaces must be followed by a letter')

.matches(/^(?!.*-[^\p{L}]).*$/u, 'Hyphens must be followed by a letter')
.matches(
/^(?!.*'[^\p{L}]).*$/u,
'Apostrophes must be followed by a letter'
),
email: yup.string().email().required()
})
Expand Down
Loading