Skip to content

Allow tilde (~) in url parameters#533

Merged
PauloGasparSv merged 4 commits into
Expensify:mainfrom
huzaifa-99:eApp/18565-allow-tilde-and-backslash-in-urls
May 15, 2023
Merged

Allow tilde (~) in url parameters#533
PauloGasparSv merged 4 commits into
Expensify:mainfrom
huzaifa-99:eApp/18565-allow-tilde-and-backslash-in-urls

Conversation

@huzaifa-99

@huzaifa-99 huzaifa-99 commented May 10, 2023

Copy link
Copy Markdown
Contributor

Fixed Issues

$ Expensify/App/issues/18564

Tests

Verify if ~ works in query params

  1. Send a valid url
  2. Verify that the sent url appears as a valid url(blue and underlined)
  3. Verify hovering over the url shows the tooltip in Web and Desktop
  4. Verify that Right click (Web and Desktop) or long press (mWeb and native) shows Copy Url to Clipboard context menu
  5. Edit the sent url
  6. Verify steps 2-4

Examples:

https://example.com/search?q=foobar~
https://example.com/search?q=~foobar
https://example.com/?~parameter~
https://example.com/?parameter~
https://example.com/?~parameter

QA

Same as tests

Screenshots/Videos

Web

Safari

web.safari.mov

Chrome

web.chrome.mov
Mobile Web - Chrome
Mweb.Chrome.mp4
Mobile Web - Safari
ios.safari.mov
Desktop
desktop.mov
iOS
Screen.Recording.2023-05-12.at.9.39.02.PM.mov
Android
Android.Native.mp4

@huzaifa-99 huzaifa-99 requested a review from a team as a code owner May 10, 2023 22:24
@github-actions

github-actions Bot commented May 10, 2023

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@huzaifa-99

This comment was marked as off-topic.

@huzaifa-99

This comment was marked as off-topic.

@sobitneupane sobitneupane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@huzaifa-99 Can you please add test video as well?

Along with the list of valid urls, please add following steps in Tests:

  1. Send a valid url
  2. Verify that the sent url appears as a valid url(blue and underlined)
  3. Verify hovering over the url shows the tooltip in Web and Desktop
  4. Verify that Right click (Web and Desktop) or long press (mWeb and native) shows Copy Url to Clipboard context menu
  5. Edit the sent url
  6. Verify steps 2-4

I don't think this PR at this moment will be sufficient to solve the case of \\.

Comment thread lib/Url.js Outdated

const ALLOWED_PORTS = '([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])';
const URL_PROTOCOL_REGEX = '((ht|f)tps?:\\/\\/)';
const URL_PROTOCOL_REGEX = '((ht|f)tps?:[\\/|\\\\]{2})';

@sobitneupane sobitneupane May 11, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you sure it is the right way to do it?

I am not an expert on regex. But I think you might have to use ( instead of [ with disjunction. I think something like
(?:\\/{2}|\\\\{2}) should do the job.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I accidently removed the second \\/, mb

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Apologies, maybe i didn't understand your comment properly. The \\/ was intentional. I will test (?:\\/{2}|\\\\{2}) with some urls and update.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your change will accept https:/\google.com and https:||google.com as valid url not only https:\\google.com

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, Thank you @sobitneupane!. I have updated with (?:\\/{2}|\\\\{2}) as you suggested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There was another place in my changes that used \\/|\\\\, fixed here

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

I don't think this PR will be sufficient to solve the case of \.

@sobitneupane just to confirm on next steps here. Should I exclude this changes for the PR? and add test for ~ only?

@sobitneupane

Copy link
Copy Markdown
Contributor

Nope. I don't mean that. I mean some other changes might be required within this repo (probably here) or in Expensify/App repo.

Did you find any issue in the PR? At the present state, I don't think PR will pass these tests.

@huzaifa-99

huzaifa-99 commented May 11, 2023

Copy link
Copy Markdown
Contributor Author

Didn't knew about the tooltip hover, thanks @sobitneupane!.
I tested and ~ in urls does work with tooltip but \\ has some issues, essentially \ works in query params ex: https://example.com/search?q=foo\\bar but not in path ex: https:\\example.com\search?q=foo\\bar.

Will check the required changes and post here soon.

@huzaifa-99

huzaifa-99 commented May 12, 2023

Copy link
Copy Markdown
Contributor Author

@sobitneupane this looks like an issue with the api. Api will recognise backslashes in some areas of the url as valid while not matching others.

In my tests, I found these urls (with backslashes) are recognised as valid by the api (and these work with tooltips/pressables)

# In query params
https://www.example.com/path/to/page.html?q=foo\\bar 
https://www.example.com/path/to/page.html?q=foo\\bar&y=john\\doe

# In path
https://www.example.com/path/to/page.html\
https://www.example.com/path/to\page.html\
https://www.example.com/path/to\page.html/
https://www.example.com/path\to\page.html/
https://www.example.com/path\to/page.html/

while these ones fail

# Trailing backslash after the TLD part
https://www.example.com/

# Backslashes after the protocol
https:\\www.example.com/

So summarising from this, API recognises backslashes when in query params or the path but not in the domain part.

Why it fails

With backslashes after the protocol or the trailing backslash after the TLD, the api responds like this. Notice that the anchor tag in the html key has no href prop.
image

For other urls the api will add the href prop
image

I also tried turning off internet. The failing urls (with backslash in domain part and trailing backslash after TLD) work when not connected to the internet, when connection is restored the api updates and it breaks the links for urls that have backslash after protocol part or the trailing backslash after TLD

Offline test
Screen.Recording.2023-05-12.at.5.51.47.PM.mov
Demo to prove above statements
Demo.URL.Backslashes-compressed.mp4

Also just for clarification, I used the same changes in this PR.

@PauloGasparSv @sobitneupane Can you please guide me on the next steps? Should we wait/hold on a change in API or just proceed with the changes in this PR?

@huzaifa-99 huzaifa-99 requested a review from sobitneupane May 12, 2023 12:59
@huzaifa-99

Copy link
Copy Markdown
Contributor Author

I will add tests soon after your response @sobitneupane

@sobitneupane

sobitneupane commented May 12, 2023

Copy link
Copy Markdown
Contributor
# Backslashes after the protocol
https:\\www.example.com/

With backslashes after the protocol or the trailing backslash after the TLD, the api responds like this. Notice that the anchor tag in the html key has no href prop.

I also tried turning off internet. The failing urls (with backslash in domain part and trailing backslash after TLD) work when not connected to the internet, when connection is restored the api updates and it breaks the links for urls that have backslash after protocol part

Oh yes. Looks like backend is returning anchor without href.

cc: @PauloGasparSv

Update: I just noticed that https:\\google.com is not considered as url in github. It will show it as https:\google.com.
Even slack doesn't consider it as url. It matches our current behavior.
Discord also doesn't consider it as url.

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

Update: I just noticed that https:\google.com is not considered as url in github. It will show it as https:\google.com.
Even slack doesn't consider it as url. It matches our current behavior.

@sobitneupane I found another case

  • Trailing backslash after TLD works in github but not in slack ex: https://google.com\

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

It matches our current behavior.

@sobitneupane just to confirm if i should add tests with \?

@sobitneupane

sobitneupane commented May 12, 2023

Copy link
Copy Markdown
Contributor

Let's wait for @PauloGasparSv's opinion on #533 (comment)

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

Sure thanks!.

Just to add to the convo, i noticed that slack doesn't allow \ anywhere in the url while Github allows it after the TLD. So https://google.com\?q=foo\\bar works in github but not in slack.

  • If we want to follow slack then we can remove the backslash changes
  • else if we want to follow Github then we need to make a small change in API to allow the trailing \ after the TLD ex: https://google.com\ and in the pr changes we need to revert the \ allowed in protocol part of the url here

@PauloGasparSv

Copy link
Copy Markdown
Contributor

I'm still trying to find time today to take a look at the API and into this.

If we want to follow slack then we can remove the backslash changes

That's really good to know! Whatsapp does allow \ in the URLS though.

Taking in consideration that:

  1. The original issue's intent which isn't specifically to make \ and \\ work but instead only ~ (this was an optional change we wanted to add)
  2. Slack and GH don't recognize that / as part of the URL so IMO it's ok to match that behavior (despite Whatsapp allowing it).
  3. The API error. I don't have a lot of time to look into this : /

I think we shouldn't bother with making \ work and only fix ~ here.

Does that sound good @sobitneupane @huzaifa-99?
That means we'll not add tests for / and we'll remove it from the regex changes here right?

@PauloGasparSv

Copy link
Copy Markdown
Contributor

Btw, thks for all the work here so far!

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

Thank you for the input @PauloGasparSv

I think we shouldn't bother with making \ work and only fix ~ here.
Does that sound good @sobitneupane @huzaifa-99?
That means we'll not add tests for / and we'll remove it from the regex changes here right?

Sounds good to me!
Yes we will have to remove the regex changes for \. I will add tests for ~ soon.

@huzaifa-99 huzaifa-99 changed the title Allow tilde (~) and double-backslash (\\) in urls Allow tilde (~) in url parameters May 12, 2023
@sobitneupane

sobitneupane commented May 12, 2023

Copy link
Copy Markdown
Contributor

@huzaifa-99 Please let me know when it is ready for review. Looks like you need to remove \\ related stuffs and update your Test steps to include test steps mentioned here.

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

@sobitneupane tests are added for all platforms, PR is ready.

Please let me know if any issues.

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

@sobitneupane bump ^

@sobitneupane sobitneupane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look good and test well.

Screenshots/Videos

Web Screenshot 2023-05-15 at 15 25 08
Mobile Web - Chrome Screenshot 2023-05-15 at 15 34 11
Mobile Web - Safari Screenshot 2023-05-15 at 15 35 20
Desktop Screenshot 2023-05-15 at 15 27 15
iOS
Android Screenshot 2023-05-15 at 16 37 29

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

Thank you @sobitneupane 🎉

@PauloGasparSv PauloGasparSv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, tested changes on Web locally!

Will test and evidences to each platform on the App P.R.

@PauloGasparSv

Copy link
Copy Markdown
Contributor

Oh the first commit here isn't signed so I can't merge this! Checking what to do here

image
image

@huzaifa-99

huzaifa-99 commented May 15, 2023

Copy link
Copy Markdown
Contributor Author

Ah apologies @PauloGasparSv.

Should I create a new PR and close this one out. I could also force push a fresh commit and remove existing ones? These are not good enough options but not sure on what's the next step.

Update: I just found out there is an option to sign previous commits but never done it. Will try and update here soon

@PauloGasparSv

Copy link
Copy Markdown
Contributor

Don't worry @huzaifa-99!

Update: I just found out there is an option to sign previous commits but never done it. Will try and update here soon

Thks for that!!!! I also searched a bit and asked for help internally, do you mind trying to:

  • Run git -c core.editor=true rebase --exec 'git commit --amend --no-edit -n -S' -i $COMMIT_HASH replacing $COMMIT_HASH with your commit hash. (Found many similar solutions online but the team recommended this one)
  • Force push (Thks for worrying about this but it's fine do to that this time)

Can you please do that and ping us @huzaifa-99?

@huzaifa-99 huzaifa-99 force-pushed the eApp/18565-allow-tilde-and-backslash-in-urls branch from a683fca to 5318124 Compare May 15, 2023 17:30
@huzaifa-99 huzaifa-99 force-pushed the eApp/18565-allow-tilde-and-backslash-in-urls branch from 5318124 to 2f762d9 Compare May 15, 2023 17:31
@huzaifa-99

Copy link
Copy Markdown
Contributor Author

@PauloGasparSv Thank you (and the team) for the solution.

I tried the command, it worked but I had to use the hash of previous commit (the commit before my unsigned commit). Anyways a lesson learned and got to know an existing commit can be signed as well. Thanks again!

@PauloGasparSv PauloGasparSv merged commit 0685262 into Expensify:main May 15, 2023
@huzaifa-99

Copy link
Copy Markdown
Contributor Author

@sobitneupane @PauloGasparSv I am not sure if i should make a PR in Expensify/App as there is already one Expensify/App#18994 that applies my commits as well.

Please let me know on the next steps. Thanks!

@sobitneupane

Copy link
Copy Markdown
Contributor

I don't think you should create another PR if there is already one which includes commit latest than yours.

cc: @PauloGasparSv

@huzaifa-99

Copy link
Copy Markdown
Contributor Author

sure, Thank you!

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.

3 participants