Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode transaction messages because they may have HTML Entities #15578

Merged
merged 1 commit into from
Mar 1, 2023

Conversation

yuwenmemon
Copy link
Contributor

@yuwenmemon yuwenmemon commented Mar 1, 2023

@aldo-expensify please review

Details

We were original showing the text here, but now that the IOU message may contain encoded HTML entities after this PR: https://github.com/Expensify/Web-Expensify/pull/36598, we should be decoding them in the front-end.

Fixed Issues

$ #15576

Tests/QA Steps

  1. Open the App
  2. Create new money request with currency without special symbol, but with abbreviation only: UAH, AFN, AMD etc
  3. check IOU details
  4. Make sure that there is no nbsp; or anything like that in the messages for the transactions

Offline tests

  • N/A

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web Screenshot 2023-02-28 at 4 12 25 PM
Mobile Web - Chrome Screenshot 2023-02-28 at 4 31 39 PM
Mobile Web - Safari Screenshot 2023-02-28 at 4 21 16 PM
Desktop Screenshot 2023-02-28 at 4 17 44 PM
iOS Screenshot 2023-02-28 at 4 22 54 PM
Android

@yuwenmemon yuwenmemon requested a review from a team as a code owner March 1, 2023 00:10
@yuwenmemon yuwenmemon self-assigned this Mar 1, 2023
@melvin-bot melvin-bot bot requested review from aimane-chnaif and thienlnam and removed request for a team March 1, 2023 00:10
@MelvinBot
Copy link

@aimane-chnaif @thienlnam One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

⚠️ ⚠️ Heads up! This pull request has the CP Staging label ⚠️ ⚠️
If you applied the CP Staging label before the PR was merged, the PR will be be immediately deployed to staging even if the open StagingDeployCash deploy checklist is locked.
However if you applied the CP Staging after the PR was merged it's possible it won't be CP'ed automatically. If you need it to be CP'ed to staging, tag a member of @Expensify/mobile-deployers to CP it manually, otherwise you can wait for it to go out with the next deploy.

Copy link
Contributor

@aldo-expensify aldo-expensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears to be working well for me. Additionally to testing with the UAH currency that shows the bug, I tested with an account with html entities in the first name:

image

Without the fix, the &s in the name were escaped:
image

With the fix, the name shows as it was original typed and the currency doesn't have   next to it anymore:
image

@aldo-expensify
Copy link
Contributor

@aimane-chnaif are you around to the reviewer checklist?

@yuwenmemon
Copy link
Contributor Author

I asked @thienlnam as well

@thienlnam
Copy link
Contributor

thienlnam commented Mar 1, 2023

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

Screenshot 2023-02-28 at 4 49 28 PM

Mobile Web - Chrome

Screenshot 2023-02-28 at 4 51 11 PM

Mobile Web - Safari

Screenshot 2023-02-28 at 4 52 54 PM

Desktop Screenshot 2023-02-28 at 4 58 34 PM
iOS

image

Android

image

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good, running through testing steps

@aldo-expensify
Copy link
Contributor

@thienlnam do you want to divide the platforms? I can give you a hand with collecting the screenshots

@thienlnam
Copy link
Contributor

@aldo-expensify If you could please help with android and desktop that would be amazing!

@aldo-expensify
Copy link
Contributor

Provided desktop, ios native, android native

@aldo-expensify aldo-expensify merged commit c35f777 into main Mar 1, 2023
@aldo-expensify aldo-expensify deleted the yuwen-decodeDollaz branch March 1, 2023 01:06
@yuwenmemon
Copy link
Contributor Author

Team work makes the dream work baby

@pecanoro
Copy link
Contributor

pecanoro commented Mar 1, 2023

Oh I left a message in the issue, this was on purpose because a contributor was fixing the front-end here #15340. We warned a few bug reporters this morning about this but we didn't warn Applause, that was my fault 🤦‍♀️

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

Performance Comparison Report 📊

Significant Changes To Duration

Name Duration
Open Search Page TTI 589.404 ms → 677.679 ms (+88.274 ms, +15.0%) 🔴
Show details
Name Duration
Open Search Page TTI Baseline
Mean: 589.404 ms
Stdev: 26.550 ms (4.5%)
Runs: 554.5615240000188 555.0400390001014 557.4374589999206 559.4126789998263 559.4697670000605 565.0596110001206 565.7572840000503 566.2372240000404 568.1432300000452 568.3330079996958 571.9672039998695 572.6036789999343 574.6500659999438 581.3766689999029 588.4140220000409 589.7870280002244 591.6835130001418 591.7174069997855 592.6289470000193 594.5769460001029 595.4775799997151 596.6275229998864 596.6762689999305 598.253173999954 603.562418999616 605.5043130000122 607.3573819999583 620.9659830001183 624.4716799999587 637.1621100003831 642.0238040001132 664.0034190001898

Current
Mean: 677.679 ms
Stdev: 43.756 ms (6.5%)
Runs: 595.3332519996911 595.9737960002385 604.6026609996334 606.9294440001249 632.0588379995897 632.0736899999902 632.347534999717 635.461873000022 639.615722999908 642.5153000000864 664.6024170001037 667.5667320000939 678.4229339999147 678.4558109999634 678.4971520002 678.9367269999348 679.6084400000982 684.400065000169 689.3195389998145 690.9715579999611 693.433960000053 695.4496659999713 701.9804689995944 705.8540449999273 710.8020840003155 712.0115149999037 717.2322599999607 719.8861899999902 720.4846200002357 721.7421880001202 749.7668869998306 751.3988850000314 755.6657310002483

Meaningless Changes To Duration

Show entries
Name Duration
App start TTI 755.089 ms → 789.974 ms (+34.885 ms, +4.6%)
App start runJsBundle 207.219 ms → 218.219 ms (+11.000 ms, +5.3%)
App start nativeLaunch 20.172 ms → 20.700 ms (+0.528 ms, +2.6%)
App start regularAppStart 0.016 ms → 0.016 ms (+0.001 ms, +3.9%)
Show details
Name Duration
App start TTI Baseline
Mean: 755.089 ms
Stdev: 28.484 ms (3.8%)
Runs: 710.0696789999492 714.8174020000733 717.4054680000991 722.5912160000298 726.4989350000396 731.3240159999114 733.2106759999879 734.0899880002253 734.2093090000562 738.1565129999071 740.1459670001641 741.7975530000404 745.1794459999073 747.7932839998975 748.2124880000483 750.9073160002008 751.401583999861 755.572371999966 762.0098729999736 762.1638869999442 763.2442830000073 763.7119200001471 764.2275890000165 770.9423789998982 771.9929080000147 776.6012750000227 782.6257990000304 796.2027010000311 810.3131450000219 813.8221990000457 826.5151530001312

Current
Mean: 789.974 ms
Stdev: 36.975 ms (4.7%)
Runs: 736.7976319999434 745.2639660001732 747.1071000001393 751.9607270001434 753.423280000221 754.4607090000063 754.8920209999196 758.7418530001305 762.1037880000658 762.9408559999429 768.2570219999179 768.5017889998853 772.9251850000583 779.6560419998132 781.4557309998199 784.6680100001395 784.8426919998601 785.342234000098 789.0057069999166 794.2055119997822 794.859432999976 800.3105009999126 801.1026909998618 806.6590149998665 810.7054730001837 823.6194629999809 825.9020910002291 831.8900979999453 835.2600469999015 855.4989080000669 859.6669160001911 897.152499999851
App start runJsBundle Baseline
Mean: 207.219 ms
Stdev: 15.249 ms (7.4%)
Runs: 174 187 188 190 192 193 193 194 196 198 199 200 203 205 206 206 207 207 208 210 212 215 215 216 216 218 219 224 227 234 234 245

Current
Mean: 218.219 ms
Stdev: 22.079 ms (10.1%)
Runs: 184 186 194 194 195 199 200 201 202 202 203 205 208 209 212 213 214 217 223 225 225 226 226 228 231 234 236 247 251 257 263 273
App start nativeLaunch Baseline
Mean: 20.172 ms
Stdev: 1.315 ms (6.5%)
Runs: 18 18 18 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 21 21 21 21 21 21 21 22 22 23 23

Current
Mean: 20.700 ms
Stdev: 1.676 ms (8.1%)
Runs: 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 20 20 21 21 21 21 21 22 22 22 23 24 25 25
App start regularAppStart Baseline
Mean: 0.016 ms
Stdev: 0.001 ms (8.1%)
Runs: 0.013590999878942966 0.013672000030055642 0.01387499994598329 0.013916000025346875 0.014038000022992492 0.014038000022992492 0.014688999857753515 0.014933000318706036 0.015055000083521008 0.015137000009417534 0.015298999845981598 0.015339999925345182 0.015422000084072351 0.015461999922990799 0.015544000081717968 0.015583999920636415 0.015746999997645617 0.015828999690711498 0.015868999995291233 0.015868999995291233 0.016398000065237284 0.016438999911770225 0.016438999911770225 0.016561000142246485 0.016600999981164932 0.016723999986425042 0.016927000135183334 0.017008000053465366 0.017455999739468098 0.017943999962881207 0.01823000004515052 0.018391999881714582

Current
Mean: 0.016 ms
Stdev: 0.001 ms (4.7%)
Runs: 0.015137000009417534 0.015381000004708767 0.015381000004708767 0.015420999843627214 0.015503000002354383 0.015583999920636415 0.01570600038394332 0.01570700015872717 0.015786999836564064 0.015828000381588936 0.015828999690711498 0.01590999960899353 0.01599099999293685 0.016032000072300434 0.016195000149309635 0.016234999988228083 0.016235999763011932 0.016478999983519316 0.016560999676585197 0.01660200022161007 0.016845999751240015 0.016885999590158463 0.01688600005581975 0.016927000135183334 0.01696800021454692 0.017090000212192535 0.017374999821186066 0.017496999818831682 0.017578000202775 0.017780999653041363 0.018025999888777733

@github-actions github-actions bot added the DeployBlockerCash This issue or pull request should block deployment label Mar 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

@Expensify/mobile-deployers 📣 Please look into this performance regression as it's a deploy blocker.

OSBotify pushed a commit that referenced this pull request Mar 1, 2023
Decode transaction messages because they may have HTML Entities

(cherry picked from commit c35f777)
OSBotify added a commit that referenced this pull request Mar 1, 2023
@OSBotify
Copy link
Contributor

OSBotify commented Mar 1, 2023

🚀 Cherry-picked to staging by https://github.com/aldo-expensify in version: 1.2.77-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@s77rt
Copy link
Contributor

s77rt commented Mar 2, 2023

@yuwenmemon @aldo-expensify I think this will cause a regression.
Ultimately the best fix here is to do nothing and decode the text in the backend, there is a conversation about this here. Due to test complexity I think we won't fix completely it in the backend (at least not for now).


Anyway, the regression I think of is if the message is: <strong>hi</strong>

  • Current behaviour: shows hi
  • After this PR: shows <strong>hi</strong>

I don't think this is intended, is it? If not then the fix would be:

Str.htmlDecode(new ExpensiMark().htmlToText(this.props.action.message[0].html));

@s77rt
Copy link
Contributor

s77rt commented Mar 2, 2023

Or we can just Str.htmlDecode(this.props.action.message[0].text) This is wrong because we are decoding a plaintext, but that plaintext is not pure plaintext (it contains html entities due to a backend bug as mentioned ^)

@aldo-expensify
Copy link
Contributor

aldo-expensify commented Mar 2, 2023

Tyler added a decode in the backend here: https://github.com/Expensify/Web-Expensify/pull/36642 (not deployed yet)

Would be good to check if maybe that made this PR unnecessary. I may be able to do some testing later.

@s77rt
Copy link
Contributor

s77rt commented Mar 2, 2023

@aldo-expensify I think it's added only for notifications, no?

@aldo-expensify
Copy link
Contributor

@aldo-expensify I think it's added only for notifications, no?

Hmm no, it was added to a function that converts the html to text for all cases I think.

@pecanoro
Copy link
Contributor

pecanoro commented Mar 2, 2023

This was for all IOU cases, not only notifications, Tyler's PR doesn't cover IOU messages. I think our code was really messy in different parts and it wasn't consistent. Some actions would decode, other ones wouldn't, some front-end would encode, other parts wouldn't...

@s77rt
Copy link
Contributor

s77rt commented Mar 2, 2023

ah cool, then it should cover IOU message as well, I don't think there is anything special about those. Let's wait for the PR to be deployed and test again, maybe this PR is not required after all

@@ -76,7 +77,7 @@ class ReportTransaction extends Component {
wrapperStyles={[styles.reportTransactionWrapper]}
>
<Text style={[styles.chatItemMessage]}>
{this.props.action.message[0].text}
{Str.htmlDecode(this.props.action.message[0].html)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be case of html not present in message.
For safety, how about fallback to text like this?

{this.props.action.message[0].html ? Str.htmlDecode(this.props.action.message[0].html) : this.props.action.message[0].text}

@OSBotify
Copy link
Contributor

OSBotify commented Mar 2, 2023

🚀 Deployed to production by https://github.com/yuwenmemon in version: 1.2.77-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Cherry-picked to staging by https://github.com/AndrewGable in version: 1.3.28-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 1.3.28-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DeployBlockerCash This issue or pull request should block deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants