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

Fix: urls for user details #4291

Merged
merged 4 commits into from
Aug 4, 2021
Merged

Conversation

parasharrajat
Copy link
Member

@parasharrajat parasharrajat commented Jul 29, 2021

Details

This issue was caused due to the reason that Url Path had . which is not being parsed in React-navigation. I have also reported the issue to React-navigation but nobody is even bothering to reply so we have to fix it with a patch in our app. I will submit a new PR as soon as I got some leads on that issue which is very unlikely.

To fix, PR does the following:

  1. Covert the route param :login to query param ?:login=xxx which fixes the issue. and routes are parsed successfully.
    e.g. https://staging.expensify.cash/details/:login to https://staging.expensify.cash/details?login=:login

Fixed Issues

$ Fixes #3924

Tests | QA Steps

  1. Open Any chat in E.cash on web.
  2. Click user avatar to see its details.
  3. refresh the page, you should land on the same page and app should not crash.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

fix-url.mp4

Mobile Web

Desktop

iOS

Android

@parasharrajat parasharrajat requested a review from a team as a code owner July 29, 2021 00:08
@MelvinBot MelvinBot requested review from chiragsalian and removed request for a team July 29, 2021 00:08
src/ROUTES.js Outdated

/**
* React Navigation is failing to parse urls with dot in the path segment.
* This method enable pasring of urls with dot in path Segment
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: switch 'enable' with 'enables'.
switch 'pasring' with 'parsing'.

src/ROUTES.js Outdated
* @param {String} path - Path for the config
* @returns {Object}
*/
getEmailRouteLinkingConfig: path => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

In the PR details you explain why you moved away from the initial solution but i don't quite understand the current solution. Can you add it to your PR or explain it to me.

Copy link
Member Author

@parasharrajat parasharrajat Jul 29, 2021

Choose a reason for hiding this comment

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

@chiragsalian We can customize the default param parsing by using the parse and stringify option for LinkingConfig.

  1. In stringify, I replace all the dots with @dot@ safely. we first encode the existing @dot@ in the URL and then do the dot conversion. Which will allow @dot@ to be part of the email.
  2. In parse, we revert to the original email by first converting @dot@ back to dot and then replace the escaped version of @dot@ back to @dot@.

This is a helper method as we need the same functionality for two of the routes and it can be used in the future for similar Routes that contain email as param.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any thoughts @chiragsalian.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah nice, i had no idea. I just read more about this here too. Well it makes sense to me and i think its fine, but i'll loop in @marcaaron too for additional thoughts.

Copy link
Member Author

Choose a reason for hiding this comment

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

@marcaaron Do you have any thoughts on this issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @marcaaron What do you think about it? Sorry for the ping.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there context on why we using @dot@?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm familiar with the url parsing features of react navigation so that part seems fine to me.

src/ROUTES.js Outdated
* @param {String} path - Path for the config
* @returns {Object}
*/
getEmailRouteLinkingConfig: path => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there context on why we using @dot@?

src/ROUTES.js Outdated
* @param {String} path - Path for the config
* @returns {Object}
*/
getEmailRouteLinkingConfig: path => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm familiar with the url parsing features of react navigation so that part seems fine to me.

src/ROUTES.js Outdated
path,
parse: {
login: l => (l
? decodeURIComponent(l).replace('@dot@', '.').replace(encodeURIComponent('@dot@'), '@dot@')
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the second .replace() achieve here? Didn't we replace with . already?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added this for safe parsing. In case the email already contains @dot@ e.g. rajat"@dot@"parashar@gmail.com. Please let me know if I have forgotten to encounter any special cases.

@dot@ I just took it based on the meaning. dot for . and @ is a special URL character that allows us to safely convert emails that can contain @dot@ as part of the string.
@ will be escaped and thus we can use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

In case the email already contains @dot@ e.g. rajat"@dot@"parashar@gmail.com. Please let me know if I have forgotten to encounter any special cases.

Sorry, not following. Why would a valid email have more than one @ let alone an @dot@ in it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok. I saw somewhere that @ can be used in quotes. I believe I overthink it. I 'll remove the extra escaping.

Copy link
Member Author

Choose a reason for hiding this comment

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

@marcaaron Updated the PR. Removed the Extra escaping stuff.

src/ROUTES.js Outdated
: undefined),
},
stringify: {
login: l => (l ? l.replace('@dot@', encodeURIComponent('@dot@')).replace('.', '@dot@') : undefined),
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic here is also confusing...

l
    .replace('@dot@', encodeURIComponent('@dot@'))
    .replace('.', '@dot@')
  • We are replacing the @dot@ with %40dot%40
  • Then we replace all . with @dot@...

Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, I have answered it above. First replace will escape the existing @dot@ from email and then we can use @dot@ to convert ..

@marcaaron
Copy link
Contributor

@parasharrajat Is there some more context on the @dot@ addition? URLs are going to look pretty weird after we do this no? Just wondering if we checked with anyone whether the weird looking urls are what we want.

@parasharrajat
Copy link
Member Author

parasharrajat commented Aug 2, 2021

I checked out on google, Using emails as URL is not a recommended thing as emails are considered private data. So if we use them in URL then it is kind of public. But we are not using any userIds so It's kind of good that the URL does not look like containing emails and bots can't read emails from it.
Thoughts 🤔 ?

@marcaaron
Copy link
Contributor

I checked out on google, Using emails as URL is not a recommended thing as emails are considered private data. So if we use them in URL then it is kind of public. But we are not using any userIds so It's kind of good that the URL does not look like containing emails and bots can't read emails from it.

  • The emails are easily accessible. What do we achieve by obscuring them in the URL only?
  • The app is used to converse with people you know and work with not random people. Maybe that will change in the future, but it's not a problem today.

we are not using any userIds so It's kind of good that the URL does not look like containing emails and bots can't read emails from it

I'm not sure this is a problem we need to solve right now, but could also not be understanding which bots we should be worried about.

To clarify, my concern is that the url looks weird and I don't see any discussion about how we landed on @dot@ or other alternatives. Is there another way to do this? e.g. query params vs. path?

@parasharrajat
Copy link
Member Author

Yeah, we can do this we Query param. This was the original Idea. But Route will not be strictly matched with the Query param.
for example, /details is equal to /details?user=xxxx;

We can definitely use query params. Let me know? Thanks.

@marcaaron
Copy link
Contributor

We could maybe bring this up in Slack? I feel others may have opinions to share.

@parasharrajat
Copy link
Member Author

parasharrajat commented Aug 2, 2021

Ok @marcaaron after discussion https://expensify.slack.com/archives/C01GTK53T8Q/p1627942434082700. I have used query params.

@parasharrajat
Copy link
Member Author

@marcaaron This is ready. Please let me know if there is something that needs to be changed.

@marcaaron
Copy link
Contributor

Thanks for the bump! Can we fix up the description so it reflects the final decision that was made?

@parasharrajat
Copy link
Member Author

Done. Thanks for mentioning that.

@chiragsalian
Copy link
Contributor

Did you retest? The moment i click on an avatar i get an error,
image

Okay looks like normal emails work. I got the failure with the email chirag+15@expensify.com which is a pretty normal test email to have. Would you be able to address this?

@parasharrajat
Copy link
Member Author

@chiragsalian Yes I retested it but I didn't test the URL with Plus. I have fixed this issue.
I think escaping is not happening for query params so I have added it myself and tested it.

Copy link
Contributor

@chiragsalian chiragsalian left a comment

Choose a reason for hiding this comment

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

Nice, LGTM and works great 👍
@marcaaron all yours.

@marcaaron marcaaron merged commit 8c06c02 into Expensify:main Aug 4, 2021
@OSBotify
Copy link
Contributor

OSBotify commented Aug 4, 2021

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Aug 6, 2021

🚀 Deployed to staging in version: 1.0.82-8🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @francoisl in version: 1.0.83-1 🚀

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

@parasharrajat parasharrajat deleted the userdetails branch November 20, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Hold for Payment 11 August] [Crash] App crashes on directly opening the user details
4 participants