From 9fea532d5c388046bfbeb1e78c538af5228bffcb Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 26 Mar 2024 18:18:53 +0700 Subject: [PATCH 1/8] validate different phone number formats --- package-lock.json | 6 +++--- package.json | 2 +- src/CONST.ts | 2 ++ src/libs/LoginUtils.ts | 2 +- src/libs/OptionsListUtils.ts | 2 +- src/libs/ReportUtils.ts | 2 +- src/libs/UserUtils.ts | 2 +- src/libs/ValidationUtils.ts | 17 ++++++++++++++++- 8 files changed, 26 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index a1b60ce853d4..8183d3fd13fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#4e020cfa13ffabde14313c92b341285aeb919f29", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#dce8e8cccd7904cc0bd17e6f455dbcd850ddc178", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -27370,8 +27370,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#4e020cfa13ffabde14313c92b341285aeb919f29", - "integrity": "sha512-sx3cIYkmiydNaXRe4kJebPyEje8HfssUbsoB6uW8vvMLwFheCZfkmF9fRMBNLo8BQsfWIstT5TApEhwuWPjqZg==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#dce8e8cccd7904cc0bd17e6f455dbcd850ddc178", + "integrity": "sha512-vHzcKvrW3S1WKxNozzhQ6qaPhssvYFsAbulo4VQ1c697+lmAHIzUsoxL6Q2+ea6xnFpZJ1BSzY2PQeG2eeH5Bw==", "license": "MIT", "dependencies": { "classnames": "2.5.0", diff --git a/package.json b/package.json index 675cc6288185..0992f3da508f 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#4e020cfa13ffabde14313c92b341285aeb919f29", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#dce8e8cccd7904cc0bd17e6f455dbcd850ddc178", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", diff --git a/src/CONST.ts b/src/CONST.ts index 3109b9ea90ca..c1f5ff1e3f32 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1681,6 +1681,8 @@ const CONST = { POLICY_ID_FROM_PATH: /\/w\/([a-zA-Z0-9]+)(\/|$)/, SHORT_MENTION: new RegExp(`@[\\w\\-\\+\\'#@]+(?:\\.[\\w\\-\\'\\+]+)*`, 'gim'), + + PHONE_NUMBER: /(\+\d{1,2}\s?)?(\(\d{3}\)|\d{3})[\s.-]?\d{3}[\s.-]?\d{4}/, }, PRONOUNS: { diff --git a/src/libs/LoginUtils.ts b/src/libs/LoginUtils.ts index 8ee6d94952f8..2d49cb992717 100644 --- a/src/libs/LoginUtils.ts +++ b/src/libs/LoginUtils.ts @@ -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}`; } diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 529ab10fab8b..4dcba503af1e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1688,7 +1688,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 diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a3ec8cebc992..664758f905d0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2930,7 +2930,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}`; diff --git a/src/libs/UserUtils.ts b/src/libs/UserUtils.ts index 147343e99ceb..ce7e4963afc7 100644 --- a/src/libs/UserUtils.ts +++ b/src/libs/UserUtils.ts @@ -210,7 +210,7 @@ function getSmallSizeAvatar(avatarSource: AvatarSource, accountID?: number): Ava */ function getSecondaryPhoneLogin(loginList: OnyxEntry): 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 { diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index cacab8333868..b06101bc30f9 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -278,13 +278,27 @@ function validateIdentity(identity: Record): Record Date: Tue, 26 Mar 2024 18:34:16 +0700 Subject: [PATCH 2/8] fix lint --- src/libs/ValidationUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index b06101bc30f9..f8d7da0c1e6b 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -1,5 +1,4 @@ import {addYears, endOfMonth, format, isAfter, isBefore, isSameDay, isValid, isWithinInterval, parse, parseISO, startOfDay, subYears} from 'date-fns'; -import Str from 'expensify-common/lib/str'; import {URL_REGEX_WITH_REQUIRED_PROTOCOL} from 'expensify-common/lib/Url'; import isDate from 'lodash/isDate'; import isEmpty from 'lodash/isEmpty'; From 4947944e749bf34244ba73d13b7b7b8d24a8c93e Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 26 Mar 2024 18:41:12 +0700 Subject: [PATCH 3/8] fix lint --- src/libs/ValidationUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index f8d7da0c1e6b..09b301bf0cd1 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -284,7 +284,7 @@ function validateIdentity(identity: Record): Record Date: Wed, 27 Mar 2024 18:17:12 +0700 Subject: [PATCH 4/8] Bump expensify-common version --- package-lock.json | 15 ++++++++------- package.json | 2 +- src/libs/ValidationUtils.ts | 18 ++---------------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 76a4bbcfb70b..35fcf119e65d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#dce8e8cccd7904cc0bd17e6f455dbcd850ddc178", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#aa2c6d204228870feb6e9b402030e3e97ece3714", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -27369,13 +27369,13 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#dce8e8cccd7904cc0bd17e6f455dbcd850ddc178", - "integrity": "sha512-vHzcKvrW3S1WKxNozzhQ6qaPhssvYFsAbulo4VQ1c697+lmAHIzUsoxL6Q2+ea6xnFpZJ1BSzY2PQeG2eeH5Bw==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#aa2c6d204228870feb6e9b402030e3e97ece3714", + "integrity": "sha512-ozlTzzsqcjF2vNItMGksfF+C1n4hoU0bEMdsRQD52SVSjzUN5NVVmkuUbysQX8BL9FzSFZccm9j8s3QDPgCXWg==", "license": "MIT", "dependencies": { "classnames": "2.5.0", "clipboard": "2.0.11", - "html-entities": "^2.4.0", + "html-entities": "^2.5.2", "jquery": "3.6.0", "localforage": "^1.10.0", "lodash": "4.17.21", @@ -29528,7 +29528,9 @@ } }, "node_modules/html-entities": { - "version": "2.4.0", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.5.2.tgz", + "integrity": "sha512-K//PSRMQk4FZ78Kyau+mZurHn3FH0Vwr+H36eE0rPbeYkRRi9YxceYPhuN60UwWorxyKHhqoAJl2OFKa4BVtaA==", "funding": [ { "type": "github", @@ -29538,8 +29540,7 @@ "type": "patreon", "url": "https://patreon.com/mdevils" } - ], - "license": "MIT" + ] }, "node_modules/html-escaper": { "version": "2.0.2", diff --git a/package.json b/package.json index 33a417de0aaa..647cb5edc7a2 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#dce8e8cccd7904cc0bd17e6f455dbcd850ddc178", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#aa2c6d204228870feb6e9b402030e3e97ece3714", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index 09b301bf0cd1..cacab8333868 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -1,4 +1,5 @@ import {addYears, endOfMonth, format, isAfter, isBefore, isSameDay, isValid, isWithinInterval, parse, parseISO, startOfDay, subYears} from 'date-fns'; +import Str from 'expensify-common/lib/str'; import {URL_REGEX_WITH_REQUIRED_PROTOCOL} from 'expensify-common/lib/Url'; import isDate from 'lodash/isDate'; import isEmpty from 'lodash/isEmpty'; @@ -277,27 +278,13 @@ function validateIdentity(identity: Record): Record Date: Fri, 29 Mar 2024 02:26:41 +0700 Subject: [PATCH 5/8] remove redundant change --- src/CONST.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index dd033ab32198..d5ad5584126c 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1690,8 +1690,6 @@ const CONST = { POLICY_ID_FROM_PATH: /\/w\/([a-zA-Z0-9]+)(\/|$)/, SHORT_MENTION: new RegExp(`@[\\w\\-\\+\\'#@]+(?:\\.[\\w\\-\\'\\+]+)*`, 'gim'), - - PHONE_NUMBER: /(\+\d{1,2}\s?)?(\(\d{3}\)|\d{3})[\s.-]?\d{3}[\s.-]?\d{4}/, }, PRONOUNS: { From c47ccffc97e9fa809795ac4f30f792d98321af19 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 29 Mar 2024 02:30:43 +0700 Subject: [PATCH 6/8] Bump expensify-common version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2bfb6ab35ac5..2c0d2a6a5622 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#f7efbd084536c140e65b49cd15f67ad8a2a10675", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#3dc943434784777f152375c4d683f3e773874007", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -27367,8 +27367,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#f7efbd084536c140e65b49cd15f67ad8a2a10675", - "integrity": "sha512-aLrSTuLNmp9yNJUhik/Uia5KaNVBKp7m+DStcPoed4hSe+tMBDT8HMez7PqO5uRC6GPFrbBr77Aa2AQOB7DVqQ==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#3dc943434784777f152375c4d683f3e773874007", + "integrity": "sha512-wbg3bEbvsjDnZUKYGCsD42tIlFS4W42+Vu2hUDrlhTs0bPMPDE2uIOHW2OJvdmPX5UpyyBB2Yft70noxLoWvaA==", "license": "MIT", "dependencies": { "classnames": "2.5.0", diff --git a/package.json b/package.json index 3abf8e2be02a..24692d646b4a 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#f7efbd084536c140e65b49cd15f67ad8a2a10675", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#3dc943434784777f152375c4d683f3e773874007", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", From b052559a95648c4c66cf7a4007152334a0dc39e7 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 1 Apr 2024 16:47:53 +0700 Subject: [PATCH 7/8] Bump expensify-common version --- package-lock.json | 6 +++--- package.json | 2 +- src/libs/ValidationUtils.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c7c70951e53e..b9ee660b5543 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#3dc943434784777f152375c4d683f3e773874007", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#2c2d3afae1465eca4642d5134be7a3ec29b67532", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -27495,8 +27495,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#3dc943434784777f152375c4d683f3e773874007", - "integrity": "sha512-wbg3bEbvsjDnZUKYGCsD42tIlFS4W42+Vu2hUDrlhTs0bPMPDE2uIOHW2OJvdmPX5UpyyBB2Yft70noxLoWvaA==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#2c2d3afae1465eca4642d5134be7a3ec29b67532", + "integrity": "sha512-FUqa4vZHuxgbj/JS8B/de25AtYwgosrZDmCVUk14NrfmhJohkDbiDRQQVxi5/mEPP862XhYslyB9o/uwgS68sA==", "license": "MIT", "dependencies": { "classnames": "2.5.0", diff --git a/package.json b/package.json index 6aac8393f498..31632a1a896f 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#3dc943434784777f152375c4d683f3e773874007", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#2c2d3afae1465eca4642d5134be7a3ec29b67532", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index cacab8333868..b1f6085f4538 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -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; } From 139c880169d890d068014f8297aee9154de7037c Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 2 Apr 2024 22:22:22 +0700 Subject: [PATCH 8/8] Bump expensify-common version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 809b4bd5c4df..c55667a21424 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#1247a822328011083a13abc769ba1911c3586338", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#dc14d9757617c1b2ebdf7c1d1816dca5b683baa2", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -27495,8 +27495,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#1247a822328011083a13abc769ba1911c3586338", - "integrity": "sha512-YqFwbL3B5XzdQ+4wmZqWcdAbRerGvP0ZvcJV2YTHETxlZdjc39AZ2gviaJhqmz8E4kTQIfgO6ii3n4bWSYKt5A==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#dc14d9757617c1b2ebdf7c1d1816dca5b683baa2", + "integrity": "sha512-FUqa4vZHuxgbj/JS8B/de25AtYwgosrZDmCVUk14NrfmhJohkDbiDRQQVxi5/mEPP862XhYslyB9o/uwgS68sA==", "license": "MIT", "dependencies": { "classnames": "2.5.0", diff --git a/package.json b/package.json index 9f1fbc894e1f..cfb98a2f317d 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#1247a822328011083a13abc769ba1911c3586338", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#dc14d9757617c1b2ebdf7c1d1816dca5b683baa2", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0",