From 0290a79b4c3c39107bef58096eced143feb88599 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Feb 2023 09:42:19 +0700 Subject: [PATCH 1/7] fix: remove decode username --- src/components/ReportActionItem/IOUQuote.js | 5 ++--- src/libs/SidebarUtils.js | 2 +- src/pages/home/report/ReportActionItemFragment.js | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/IOUQuote.js b/src/components/ReportActionItem/IOUQuote.js index 2dd1f2da74b..c0bfbdc8645 100644 --- a/src/components/ReportActionItem/IOUQuote.js +++ b/src/components/ReportActionItem/IOUQuote.js @@ -2,7 +2,6 @@ import React from 'react'; import {View, Pressable} from 'react-native'; import PropTypes from 'prop-types'; import _ from 'underscore'; -import Str from 'expensify-common/lib/str'; import Text from '../Text'; import Icon from '../Icon'; import * as Expensicons from '../Icon/Expensicons'; @@ -70,14 +69,14 @@ const IOUQuote = props => ( {/* Get first word of IOU message */} - {Str.htmlDecode(fragment.text.split(' ')[0])} + {fragment.text.split(' ')[0]} {/* Get remainder of IOU message */} - {Str.htmlDecode(fragment.text.substring(fragment.text.indexOf(' ')))} + {fragment.text.substring(fragment.text.indexOf(' '))} diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index ceb8c449b17..74579557299 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -246,7 +246,7 @@ function getOptionData(reportID) { if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else { - lastMessageTextFromReport = Str.htmlDecode(report ? report.lastMessageText : ''); + lastMessageTextFromReport = report ? report.lastMessageText : ''; } const lastActorDetails = personalDetails[report.lastActorEmail] || null; diff --git a/src/pages/home/report/ReportActionItemFragment.js b/src/pages/home/report/ReportActionItemFragment.js index c4f593517df..e8a4be8ce2f 100644 --- a/src/pages/home/report/ReportActionItemFragment.js +++ b/src/pages/home/report/ReportActionItemFragment.js @@ -142,7 +142,7 @@ const ReportActionItemFragment = (props) => { numberOfLines={props.isSingleLine ? 1 : undefined} style={[styles.chatItemMessageHeaderSender]} > - {Str.htmlDecode(props.fragment.text)} + {props.fragment.text} ); From 478f1aa86d442533273e294c8600f785ba9ac079 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 1 Mar 2023 00:45:55 +0700 Subject: [PATCH 2/7] fix: decode IOU message --- src/components/ReportActionItem/IOUQuote.js | 5 +++-- .../Notification/LocalNotification/BrowserNotifications.js | 2 +- src/libs/ReportUtils.js | 3 ++- src/libs/SidebarUtils.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/IOUQuote.js b/src/components/ReportActionItem/IOUQuote.js index c0bfbdc8645..2dd1f2da74b 100644 --- a/src/components/ReportActionItem/IOUQuote.js +++ b/src/components/ReportActionItem/IOUQuote.js @@ -2,6 +2,7 @@ import React from 'react'; import {View, Pressable} from 'react-native'; import PropTypes from 'prop-types'; import _ from 'underscore'; +import Str from 'expensify-common/lib/str'; import Text from '../Text'; import Icon from '../Icon'; import * as Expensicons from '../Icon/Expensicons'; @@ -69,14 +70,14 @@ const IOUQuote = props => ( {/* Get first word of IOU message */} - {fragment.text.split(' ')[0]} + {Str.htmlDecode(fragment.text.split(' ')[0])} {/* Get remainder of IOU message */} - {fragment.text.substring(fragment.text.indexOf(' '))} + {Str.htmlDecode(fragment.text.substring(fragment.text.indexOf(' ')))} diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.js b/src/libs/Notification/LocalNotification/BrowserNotifications.js index 8b00870312c..2529113aecc 100644 --- a/src/libs/Notification/LocalNotification/BrowserNotifications.js +++ b/src/libs/Notification/LocalNotification/BrowserNotifications.js @@ -107,7 +107,7 @@ export default { */ pushReportCommentNotification({reportAction, onClick}, usesIcon = false) { const {person, message} = reportAction; - const plainTextPerson = Str.htmlDecode(_.map(person, f => f.text).join()); + const plainTextPerson = _.map(person, f => f.text).join(); // Specifically target the comment part of the message const plainTextMessage = Str.htmlDecode((_.find(message, f => f.type === 'COMMENT') || {}).text); diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 21e8884b926..ee5f2f21e0f 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -883,7 +883,8 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu */ function getIOUReportActionMessage(type, total, participants, comment, currency, paymentType = '', isSettlingUp = false) { const amount = NumberFormatUtils.format(preferredLocale, total / 100, {style: 'currency', currency}); - const displayNames = _.map(participants, participant => getDisplayNameForParticipant(participant.login, true)); + const parser = new ExpensiMark(); + const displayNames = _.map(participants, participant => parser.replace(getDisplayNameForParticipant(participant.login, true))); const who = displayNames.length < 3 ? displayNames.join(' and ') : `${displayNames.slice(0, -1).join(', ')}, and ${_.last(displayNames)}`; diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 74579557299..ceb8c449b17 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -246,7 +246,7 @@ function getOptionData(reportID) { if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else { - lastMessageTextFromReport = report ? report.lastMessageText : ''; + lastMessageTextFromReport = Str.htmlDecode(report ? report.lastMessageText : ''); } const lastActorDetails = personalDetails[report.lastActorEmail] || null; From 87d468954eff24ca7f52189313e3f6325446454a Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 1 Mar 2023 08:43:47 +0700 Subject: [PATCH 3/7] fix: decode message in iou detail --- src/components/ReportTransaction.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index be53b11c742..a1856fc87a8 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -1,6 +1,7 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {View} from 'react-native'; +import Str from 'expensify-common/lib/str'; import styles from '../styles/styles'; import CONST from '../CONST'; import * as IOU from '../libs/actions/IOU'; @@ -76,7 +77,7 @@ class ReportTransaction extends Component { wrapperStyles={[styles.reportTransactionWrapper]} > - {this.props.action.message[0].text} + {Str.htmlDecode(this.props.action.message[0].text)} {this.props.canBeRejected && ( From 6b7f5bc4982db4eae1c9c5dbbf613041dc4307c6 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 2 Mar 2023 22:38:43 +0700 Subject: [PATCH 4/7] replace parser.replace by htmlEncode and encode comment --- src/libs/ReportUtils.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7d829d08745..722db49f662 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -883,12 +883,11 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu */ function getIOUReportActionMessage(type, total, participants, comment, currency, paymentType = '', isSettlingUp = false) { const amount = NumberFormatUtils.format(preferredLocale, total / 100, {style: 'currency', currency}); - const parser = new ExpensiMark(); - const displayNames = _.map(participants, participant => parser.replace(getDisplayNameForParticipant(participant.login, true))); + const displayNames = _.map(participants, participant => Str.htmlEncode(getDisplayNameForParticipant(participant.login, true))); const who = displayNames.length < 3 ? displayNames.join(' and ') : `${displayNames.slice(0, -1).join(', ')}, and ${_.last(displayNames)}`; - + const encodedComment = Str.htmlEncode(comment); let paymentMethodMessage; switch (paymentType) { case CONST.IOU.PAYMENT_TYPE.EXPENSIFY: @@ -907,21 +906,21 @@ function getIOUReportActionMessage(type, total, participants, comment, currency, let iouMessage; switch (type) { case CONST.IOU.REPORT_ACTION_TYPE.CREATE: - iouMessage = `Requested ${amount} from ${who}${comment && ` for ${comment}`}`; + iouMessage = `Requested ${amount} from ${who}${comment && ` for ${encodedComment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.SPLIT: - iouMessage = `Split ${amount} with ${who}${comment && ` for ${comment}`}`; + iouMessage = `Split ${amount} with ${who}${comment && ` for ${encodedComment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.CANCEL: - iouMessage = `Cancelled the ${amount} request${comment && ` for ${comment}`}`; + iouMessage = `Cancelled the ${amount} request${comment && ` for ${encodedComment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.DECLINE: - iouMessage = `Declined the ${amount} request${comment && ` for ${comment}`}`; + iouMessage = `Declined the ${amount} request${comment && ` for ${encodedComment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.PAY: iouMessage = isSettlingUp ? `Settled up${paymentMethodMessage}` - : `Sent ${amount}${comment && ` for ${comment}`}${paymentMethodMessage}`; + : `Sent ${amount}${comment && ` for ${encodedComment}`}${paymentMethodMessage}`; break; default: break; From c3adbb96cbc66de30452b916aeb55b13e6dc16a3 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 8 Mar 2023 00:22:28 +0700 Subject: [PATCH 5/7] fix: decode html instead of text --- src/components/ReportActionItem/IOUQuote.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/IOUQuote.js b/src/components/ReportActionItem/IOUQuote.js index 032297505a7..17d29b3597a 100644 --- a/src/components/ReportActionItem/IOUQuote.js +++ b/src/components/ReportActionItem/IOUQuote.js @@ -83,7 +83,7 @@ const IOUQuote = props => ( : styles.cursorDefault]} > {/* Get remainder of IOU message */} - {Str.htmlDecode(fragment.text.substring(fragment.text.indexOf(' ')))} + {Str.htmlDecode(fragment.html.substring(fragment.html.indexOf(' ')))} From 7067ae8de581012065e107951aaa71f76f7175a9 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Mar 2023 01:51:53 +0700 Subject: [PATCH 6/7] fix: remove Str.htmlDecode --- src/components/ReportActionItem/IOUQuote.js | 5 ++--- src/components/ReportTransaction.js | 3 +-- .../LocalNotification/BrowserNotifications.js | 3 +-- src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.js | 13 ++++++------- src/libs/SidebarUtils.js | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/components/ReportActionItem/IOUQuote.js b/src/components/ReportActionItem/IOUQuote.js index 17d29b3597a..f93888d4144 100644 --- a/src/components/ReportActionItem/IOUQuote.js +++ b/src/components/ReportActionItem/IOUQuote.js @@ -2,7 +2,6 @@ import React from 'react'; import {View, Pressable} from 'react-native'; import PropTypes from 'prop-types'; import _ from 'underscore'; -import Str from 'expensify-common/lib/str'; import Text from '../Text'; import Icon from '../Icon'; import * as Expensicons from '../Icon/Expensicons'; @@ -76,14 +75,14 @@ const IOUQuote = props => ( {/* Get first word of IOU message */} - {Str.htmlDecode(fragment.text.split(' ')[0])} + {fragment.text.split(' ')[0]} {/* Get remainder of IOU message */} - {Str.htmlDecode(fragment.html.substring(fragment.html.indexOf(' ')))} + {fragment.text.substring(fragment.text.indexOf(' '))} diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 5586f5e67c2..be53b11c742 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -1,7 +1,6 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {View} from 'react-native'; -import Str from 'expensify-common/lib/str'; import styles from '../styles/styles'; import CONST from '../CONST'; import * as IOU from '../libs/actions/IOU'; @@ -77,7 +76,7 @@ class ReportTransaction extends Component { wrapperStyles={[styles.reportTransactionWrapper]} > - {Str.htmlDecode(this.props.action.message[0].html)} + {this.props.action.message[0].text} {this.props.canBeRejected && ( diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.js b/src/libs/Notification/LocalNotification/BrowserNotifications.js index 2529113aecc..170f05aacf7 100644 --- a/src/libs/Notification/LocalNotification/BrowserNotifications.js +++ b/src/libs/Notification/LocalNotification/BrowserNotifications.js @@ -1,6 +1,5 @@ // Web and desktop implementation only. Do not import for direct use. Use LocalNotification. import _ from 'underscore'; -import Str from 'expensify-common/lib/str'; import focusApp from './focusApp'; import * as AppUpdate from '../../actions/AppUpdate'; import EXPENSIFY_ICON_URL from '../../../../assets/images/expensify-logo-round-clearspace.png'; @@ -110,7 +109,7 @@ export default { const plainTextPerson = _.map(person, f => f.text).join(); // Specifically target the comment part of the message - const plainTextMessage = Str.htmlDecode((_.find(message, f => f.type === 'COMMENT') || {}).text); + const plainTextMessage = (_.find(message, f => f.type === 'COMMENT') || {}).text; push({ title: plainTextPerson, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index bf88721ae0a..ae9535622a8 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -327,7 +327,7 @@ function createOption(logins, personalDetails, report, reportActions = {}, { if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else { - lastMessageTextFromReport = Str.htmlDecode(report ? report.lastMessageText : ''); + lastMessageTextFromReport = report ? report.lastMessageText : ''; } const lastActorDetails = personalDetailMap[report.lastActorEmail] || null; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 2954ceee7da..bfbdb59aa2c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -955,11 +955,10 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu */ function getIOUReportActionMessage(type, total, participants, comment, currency, paymentType = '', isSettlingUp = false) { const amount = NumberFormatUtils.format(preferredLocale, total / 100, {style: 'currency', currency}); - const displayNames = _.map(participants, participant => Str.htmlEncode(getDisplayNameForParticipant(participant.login, true))); + const displayNames = _.map(participants, participant => getDisplayNameForParticipant(participant.login, true)); const who = displayNames.length < 3 ? displayNames.join(' and ') : `${displayNames.slice(0, -1).join(', ')}, and ${_.last(displayNames)}`; - const encodedComment = Str.htmlEncode(comment); let paymentMethodMessage; switch (paymentType) { case CONST.IOU.PAYMENT_TYPE.EXPENSIFY: @@ -978,21 +977,21 @@ function getIOUReportActionMessage(type, total, participants, comment, currency, let iouMessage; switch (type) { case CONST.IOU.REPORT_ACTION_TYPE.CREATE: - iouMessage = `Requested ${amount} from ${who}${comment && ` for ${encodedComment}`}`; + iouMessage = `Requested ${amount} from ${who}${comment && ` for ${comment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.SPLIT: - iouMessage = `Split ${amount} with ${who}${comment && ` for ${encodedComment}`}`; + iouMessage = `Split ${amount} with ${who}${comment && ` for ${comment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.CANCEL: - iouMessage = `Cancelled the ${amount} request${comment && ` for ${encodedComment}`}`; + iouMessage = `Cancelled the ${amount} request${comment && ` for ${comment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.DECLINE: - iouMessage = `Declined the ${amount} request${comment && ` for ${encodedComment}`}`; + iouMessage = `Declined the ${amount} request${comment && ` for ${comment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.PAY: iouMessage = isSettlingUp ? `Settled up${paymentMethodMessage}` - : `Sent ${amount}${comment && ` for ${encodedComment}`}${paymentMethodMessage}`; + : `Sent ${amount}${comment && ` for ${comment}`}${paymentMethodMessage}`; break; default: break; diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 5cf2514efcd..dd136eba365 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -246,7 +246,7 @@ function getOptionData(reportID) { if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else { - lastMessageTextFromReport = Str.htmlDecode(report ? report.lastMessageText : ''); + lastMessageTextFromReport = report ? report.lastMessageText : ''; } const lastActorDetails = personalDetails[report.lastActorEmail] || null; From 6a0a7f9a71aa8ec2656799c6a1de7d0636a5c6f8 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 27 Mar 2023 19:03:53 +0700 Subject: [PATCH 7/7] remove htmlDecode applied on plaintext --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index fdb176edcb8..d57a559c339 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -472,7 +472,7 @@ function getLastMessageText(report) { } return isReportMessageAttachment({text: lastReportActionText, html: lastReportActionHtml}) ? `[${Localize.translateLocal('common.attachment')}]` - : Str.htmlDecode(lastReportActionText); + : lastReportActionText; } /**