From a94568b3f01a45a7614adfc56150e81c63192bd4 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Wed, 1 Mar 2023 16:56:13 +0200 Subject: [PATCH 1/5] Allow searching for phone numbers with parenthesis, spaces and dashes in them --- src/CONST.js | 1 + src/libs/OptionsListUtils.js | 4 +++- tests/unit/OptionsListUtilsTest.js | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index 30f9e24ae3e7..64f2f7bc65af 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -808,6 +808,7 @@ const CONST = { EMOJIS: /[\p{Extended_Pictographic}\u200d\u{1f1e6}-\u{1f1ff}\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}\u20E3\uFE0F]|[#*0-9]\uFE0F?\u20E3/gu, TAX_ID: /^\d{9}$/, NON_NUMERIC: /\D/g, + NON_NUMERIC_WITH_PLUS: /[^0-9+]/g, EMOJI_NAME: /:[\w+-]+:/g, EMOJI_SUGGESTIONS: /:[a-zA-Z0-9_+-]{1,40}$/, AFTER_FIRST_LINE_BREAK: /\n.*/g, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0f8c3828a543..42f6aeeedff1 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -703,9 +703,11 @@ function getNewChatOptions( selectedOptions = [], excludeLogins = [], ) { + const isPhoneNumber = CONST.REGEX.PHONE_WITH_SPECIAL_CHARS.test(searchValue); + return getOptions(reports, personalDetails, { betas, - searchValue: searchValue.trim(), + searchValue: isPhoneNumber ? searchValue.replace(CONST.REGEX.NON_NUMERIC_WITH_PLUS, '') : searchValue.trim(), selectedOptions, excludeChatRooms: true, includeRecentReports: true, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index c48dec63801f..ef3364aab291 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -515,6 +515,17 @@ describe('OptionsListUtils', () => { expect(results.userToInvite).not.toBe(null); expect(results.userToInvite.login).toBe('+15005550006'); + // When we add a search term for which no options exist and the searchValue itself + // is a potential phone number with special characters added + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '(800) 324-323'); + + // Then we should have no options or personal details at all but there should be a userToInvite and the login + // should have the country code included + expect(results.recentReports.length).toBe(0); + expect(results.personalDetails.length).toBe(0); + expect(results.userToInvite).not.toBe(null); + expect(results.userToInvite.login).toBe('+1800324323'); + // Test Concierge's existence in new group options results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); From 70b1d52d73df7fd38427fec5bd0419ed50c30cdf Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Wed, 1 Mar 2023 17:22:34 +0200 Subject: [PATCH 2/5] migrate to global solution --- src/libs/OptionsListUtils.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 42f6aeeedff1..cc45e6dad8f0 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -442,7 +442,7 @@ function getOptions(reports, personalDetails, { // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. sortByReportTypeInSearch = false, - searchValue = '', + searchInputValue = '', showChatPreviewLine = false, sortPersonalDetailsByAlphaAsc = true, forcePolicyNamePreview = false, @@ -450,6 +450,8 @@ function getOptions(reports, personalDetails, { let recentReportOptions = []; let personalDetailsOptions = []; const reportMapForLogins = {}; + const isPhoneNumber = CONST.REGEX.PHONE_WITH_SPECIAL_CHARS.test(searchInputValue); + const searchValue = isPhoneNumber ? searchInputValue.replace(CONST.REGEX.NON_NUMERIC_WITH_PLUS, '') : searchInputValue; // Filter out all the reports that shouldn't be displayed const filteredReports = _.filter(reports, report => ReportUtils.shouldReportBeInOptionList( @@ -641,7 +643,7 @@ function getSearchOptions( ) { return getOptions(reports, personalDetails, { betas, - searchValue: searchValue.trim(), + searchInputValue: searchValue.trim(), includeRecentReports: true, includeMultipleParticipantReports: true, maxRecentReportsToShow: 0, // Unlimited @@ -703,11 +705,9 @@ function getNewChatOptions( selectedOptions = [], excludeLogins = [], ) { - const isPhoneNumber = CONST.REGEX.PHONE_WITH_SPECIAL_CHARS.test(searchValue); - return getOptions(reports, personalDetails, { betas, - searchValue: isPhoneNumber ? searchValue.replace(CONST.REGEX.NON_NUMERIC_WITH_PLUS, '') : searchValue.trim(), + searchInputValue: searchValue.trim(), selectedOptions, excludeChatRooms: true, includeRecentReports: true, @@ -734,7 +734,7 @@ function getMemberInviteOptions( ) { return getOptions([], personalDetails, { betas, - searchValue: searchValue.trim(), + searchInputValue: searchValue.trim(), excludeDefaultRooms: true, includePersonalDetails: true, excludeLogins, From 67ea1a5fdcb4b72ce10ccbfc0204ea5ed834884d Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Wed, 1 Mar 2023 18:21:35 +0200 Subject: [PATCH 3/5] change reg exp --- src/CONST.js | 1 + src/libs/OptionsListUtils.js | 2 +- tests/unit/OptionsListUtilsTest.js | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 64f2f7bc65af..8bddf196735a 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -786,6 +786,7 @@ const CONST = { DIGITS_AND_PLUS: /^\+?[0-9]*$/, PHONE_E164_PLUS: /^\+?[1-9]\d{1,14}$/, PHONE_WITH_SPECIAL_CHARS: /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\\./0-9]{0,12}$/, + PHONE_WITH_ANY_CHARS: /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/, ALPHABETIC_CHARS: /[a-zA-Z]+/, POSITIVE_INTEGER: /^\d+$/, NON_ALPHA_NUMERIC: /[^A-Za-z0-9+]/g, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index cc45e6dad8f0..673ac42a014d 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -450,7 +450,7 @@ function getOptions(reports, personalDetails, { let recentReportOptions = []; let personalDetailsOptions = []; const reportMapForLogins = {}; - const isPhoneNumber = CONST.REGEX.PHONE_WITH_SPECIAL_CHARS.test(searchInputValue); + const isPhoneNumber = CONST.REGEX.PHONE_WITH_ANY_CHARS.test(searchInputValue); const searchValue = isPhoneNumber ? searchInputValue.replace(CONST.REGEX.NON_NUMERIC_WITH_PLUS, '') : searchInputValue; // Filter out all the reports that shouldn't be displayed diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index ef3364aab291..8a71c44e8825 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -517,14 +517,14 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is a potential phone number with special characters added - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '(800) 324-323'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+1 (800)324-3233'); // Then we should have no options or personal details at all but there should be a userToInvite and the login // should have the country code included expect(results.recentReports.length).toBe(0); expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+1800324323'); + expect(results.userToInvite.login).toBe('+18003243233'); // Test Concierge's existence in new group options results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); From 33e17d04f1a4382a298f4b8f54866488d417944e Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Thu, 2 Mar 2023 19:35:28 +0200 Subject: [PATCH 4/5] remove unused regexp --- src/CONST.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index 8bddf196735a..b36d1a7ebfcf 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -785,7 +785,6 @@ const CONST = { US_PHONE_WITH_OPTIONAL_COUNTRY_CODE: /^(\+1)?\d{10}$/, DIGITS_AND_PLUS: /^\+?[0-9]*$/, PHONE_E164_PLUS: /^\+?[1-9]\d{1,14}$/, - PHONE_WITH_SPECIAL_CHARS: /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\\./0-9]{0,12}$/, PHONE_WITH_ANY_CHARS: /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/, ALPHABETIC_CHARS: /[a-zA-Z]+/, POSITIVE_INTEGER: /^\d+$/, From 8690bd722fa9cecc85fdd8c930ccb87d9582e4f3 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Thu, 2 Mar 2023 19:40:27 +0200 Subject: [PATCH 5/5] change namings for regexp --- src/CONST.js | 2 +- src/libs/OptionsListUtils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index b36d1a7ebfcf..9e5823138368 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -785,7 +785,7 @@ const CONST = { US_PHONE_WITH_OPTIONAL_COUNTRY_CODE: /^(\+1)?\d{10}$/, DIGITS_AND_PLUS: /^\+?[0-9]*$/, PHONE_E164_PLUS: /^\+?[1-9]\d{1,14}$/, - PHONE_WITH_ANY_CHARS: /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/, + PHONE_WITH_SPECIAL_CHARS: /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/, ALPHABETIC_CHARS: /[a-zA-Z]+/, POSITIVE_INTEGER: /^\d+$/, NON_ALPHA_NUMERIC: /[^A-Za-z0-9+]/g, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 673ac42a014d..cc45e6dad8f0 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -450,7 +450,7 @@ function getOptions(reports, personalDetails, { let recentReportOptions = []; let personalDetailsOptions = []; const reportMapForLogins = {}; - const isPhoneNumber = CONST.REGEX.PHONE_WITH_ANY_CHARS.test(searchInputValue); + const isPhoneNumber = CONST.REGEX.PHONE_WITH_SPECIAL_CHARS.test(searchInputValue); const searchValue = isPhoneNumber ? searchInputValue.replace(CONST.REGEX.NON_NUMERIC_WITH_PLUS, '') : searchInputValue; // Filter out all the reports that shouldn't be displayed