-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updated with changes #1598
base: develop
Are you sure you want to change the base?
updated with changes #1598
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,11 +40,17 @@ const registrationBodyValidation = joi.object({ | |
firstName: joi | ||
.string() | ||
.required() | ||
.pattern(/^[A-Za-z]+$/), | ||
.pattern(/^[\p{L}]+(?:[\p{L}\s]+)*$/u) | ||
.messages({ | ||
"string.pattern.base": "First name must contain only letters and spaces", | ||
}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Yo, the regex is dropping the ball on legit names! 🎯 The current pattern is too restrictive and fails to validate common name formats:
While it correctly handles Unicode letters (José, María, 안녕하세요), it needs to be updated to support these common name components. 🔗 Analysis chainVerify the regex pattern coverage! 🎯 Let's make sure our regex pattern handles all the edge cases correctly. Also applies to: 50-53, 81-92 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Test the name validation regex against various test cases
# Create a test file with sample names
cat << 'EOF' > test_names.txt
John
Mary-Jane
O'Connor
José
María
안녕하세요
Zhang-Wei
Jean-François
Smith Jr.
EOF
# Use awk to test the regex pattern against each name
awk '
BEGIN {
pattern = "^[[:alpha:]]+([[:alpha:][:space:]'\''\\-]+)*$"
}
{
if ($0 ~ pattern) {
print "PASS:", $0
} else {
print "FAIL:", $0
}
}' test_names.txt
Length of output: 329 Script: #!/bin/bash
# Create a Node.js script to test the actual regex pattern
cat << 'EOF' > test_regex.js
const names = [
'John',
'Mary-Jane',
"O'Connor",
'José',
'María',
'안녕하세요',
'Zhang-Wei',
'Jean-François',
'Smith Jr.',
'John123',
'Mary!',
' Space',
'Dot.Name'
];
const pattern = /^[\p{L}]+(?:[\p{L}\s]+)*$/u;
console.log('Testing names against pattern:', pattern);
console.log('----------------------------------------');
names.forEach(name => {
console.log(`${name.padEnd(20)} : ${pattern.test(name) ? 'PASS' : 'FAIL'}`);
});
EOF
# Use Node.js to run the test
node test_regex.js
Length of output: 491 |
||
lastName: joi | ||
.string() | ||
.required() | ||
.pattern(/^[A-Za-z]+$/), | ||
.pattern(/^[\p{L}]+(?:[\p{L}\s]+)*$/u) | ||
.messages({ | ||
"string.pattern.base": "Last name must contain only letters and spaces", | ||
}), | ||
email: joi | ||
.string() | ||
.email() | ||
|
@@ -72,8 +78,18 @@ const editUserParamValidation = joi.object({ | |
}); | ||
|
||
const editUserBodyValidation = joi.object({ | ||
firstName: joi.string().pattern(/^[A-Za-z]+$/), | ||
lastName: joi.string().pattern(/^[A-Za-z]+$/), | ||
firstName: joi | ||
.string() | ||
.pattern(/^[\p{L}]+(?:[\p{L}\s]+)*$/u) | ||
.messages({ | ||
"string.pattern.base": "First name must contain only letters and spaces", | ||
}), | ||
lastName: joi | ||
.string() | ||
.pattern(/^[\p{L}]+(?:[\p{L}\s]+)*$/u) | ||
.messages({ | ||
"string.pattern.base": "Last name must contain only letters and spaces", | ||
}), | ||
profileImage: joi.any(), | ||
newPassword: joi.string().min(8).pattern(passwordPattern), | ||
password: joi.string().min(8).pattern(passwordPattern), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo, the name validation needs more flexibility, dawg! 🔥
The current regex pattern doesn't support common name characters like hyphens (e.g., "Anne-Marie") and apostrophes (e.g., "O'Connor"). Let's make it more inclusive!
Here's a fix that'll make it work better:
Also applies to: 14-14