Skip to content

Commit

Permalink
Merge pull request #38993 from tienifr/fix/37723
Browse files Browse the repository at this point in the history
Validate different phone number formats
  • Loading branch information
grgia authored Apr 3, 2024
2 parents ff492c4 + 467b1b0 commit 7177173
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libs/LoginUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function isEmailPublicDomain(email: string): boolean {
function validateNumber(values: string): string {
const parsedPhoneNumber = parsePhoneNumber(values);

if (parsedPhoneNumber.possible && Str.isValidPhone(values.slice(0))) {
if (parsedPhoneNumber.possible && Str.isValidE164Phone(values.slice(0))) {
return `${parsedPhoneNumber.number?.e164}${CONST.SMS.DOMAIN}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ function getOptions(
!isCurrentUser({login: searchValue} as PersonalDetails) &&
selectedOptions.every((option) => 'login' in option && option.login !== searchValue) &&
((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue) && !Str.endsWith(searchValue, CONST.SMS.DOMAIN)) ||
(parsedPhoneNumber.possible && Str.isValidPhone(LoginUtils.getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number?.input ?? '')))) &&
(parsedPhoneNumber.possible && Str.isValidE164Phone(LoginUtils.getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number?.input ?? '')))) &&
!optionsToExclude.find((optionToExclude) => 'login' in optionToExclude && optionToExclude.login === PhoneNumber.addSMSDomainIfPhoneNumber(searchValue).toLowerCase()) &&
(searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) &&
!excludeUnknownUsers
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,7 @@ function getParsedComment(text: string): string {
return `@${mentionWithEmailDomain}`;
}
}
if (Str.isValidPhone(mention)) {
if (Str.isValidE164Phone(mention)) {
const mentionWithSmsDomain = PhoneNumber.addSMSDomainIfPhoneNumber(mention);
if (allPersonalDetailLogins.includes(mentionWithSmsDomain)) {
return `@${mentionWithSmsDomain}`;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/UserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function getSmallSizeAvatar(avatarSource: AvatarSource, accountID?: number): Ava
*/
function getSecondaryPhoneLogin(loginList: OnyxEntry<Login>): string | undefined {
const parsedLoginList = Object.keys(loginList ?? {}).map((login) => Str.removeSMSDomain(login));
return parsedLoginList.find((login) => Str.isValidPhone(login));
return parsedLoginList.find((login) => Str.isValidE164Phone(login));
}

export {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function isValidUSPhone(phoneNumber = '', isCountryCodeOptional?: boolean): bool

// When we pass regionCode as an option to parsePhoneNumber it wrongly assumes inputs like '=15123456789' as valid
// so we need to check if it is a valid phone.
if (regionCode && !Str.isValidPhone(phone)) {
if (regionCode && !Str.isValidPhoneFormat(phone)) {
return false;
}

Expand Down

0 comments on commit 7177173

Please sign in to comment.