Skip to content

Commit

Permalink
Merge pull request #28125 from namhihi237/fix27582-copy-open-deep-link
Browse files Browse the repository at this point in the history
update get contract method from url when open deep link
  • Loading branch information
pecanoro authored Sep 29, 2023
2 parents 4ebeea0 + 049cccd commit b94c32c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,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: {
Expand Down
18 changes: 17 additions & 1 deletion src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit b94c32c

Please sign in to comment.