From 049cccda0f2e05e78552f55524212e72adf3816c Mon Sep 17 00:00:00 2001 From: Nam Le Date: Mon, 25 Sep 2023 17:03:02 +0700 Subject: [PATCH] update get contract method from url when open deep link --- src/CONST.ts | 2 ++ .../Contacts/ContactMethodDetailsPage.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/CONST.ts b/src/CONST.ts index 3a198aca2c8c..e3da90c3428c 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1252,6 +1252,8 @@ const CONST = { DATE_TIME_FORMAT: /^\d{2}-\d{2} \d{2}:\d{2} [AP]M$/, ATTACHMENT_ROUTE: /\/r\/(\d*)\/attachment/, ILLEGAL_FILENAME_CHARACTERS: /\/|<|>|\*|"|:|\?|\\|\|/g, + + ENCODE_PERCENT_CHARACTER: /%(25)+/g, }, PRONOUNS: { diff --git a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js index b8c817350a38..79d5f96aaefb 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js @@ -25,6 +25,7 @@ import ValidateCodeForm from './ValidateCodeForm'; import ROUTES from '../../../../ROUTES'; import FullscreenLoadingIndicator from '../../../../components/FullscreenLoadingIndicator'; import FullPageNotFoundView from '../../../../components/BlockingViews/FullPageNotFoundView'; +import CONST from '../../../../CONST'; const propTypes = { /* Onyx Props */ @@ -131,7 +132,22 @@ class ContactMethodDetailsPage extends Component { * @returns {string} */ getContactMethod() { - return decodeURIComponent(lodashGet(this.props.route, 'params.contactMethod')); + const contactMethod = lodashGet(this.props.route, 'params.contactMethod'); + + // We find the number of times the url is encoded based on the last % sign and remove them. + const lastPercentIndex = contactMethod.lastIndexOf('%'); + const encodePercents = contactMethod.substring(lastPercentIndex).match(new RegExp('25', 'g')); + let numberEncodePercents = encodePercents ? encodePercents.length : 0; + const beforeAtSign = contactMethod.substring(0, lastPercentIndex).replace(CONST.REGEX.ENCODE_PERCENT_CHARACTER, (match) => { + if (numberEncodePercents > 0) { + numberEncodePercents--; + return '%'; + } + return match; + }); + const afterAtSign = contactMethod.substring(lastPercentIndex).replace(CONST.REGEX.ENCODE_PERCENT_CHARACTER, '%'); + + return decodeURIComponent(beforeAtSign + afterAtSign); } /**