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

Any links pasted into e.cash that includes a colon : break causing only the portion before the colon to be hyperlinked #4105

Closed
isagoico opened this issue Jul 16, 2021 · 22 comments
Assignees
Labels
Engineering External Added to denote the issue can be worked on by a contributor Improvement Item broken or needs improvement. Weekly KSv2

Comments

@isagoico
Copy link

isagoico commented Jul 16, 2021

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Log in to e.cash and navigate to a conversation
  2. Paste and send these links that contain colons:
    A. https://www.google.com/maps/place/%E9%9D%92%E5%B3%B6%E9%80%A3%E7%B5%A1%E8%88%B9%E4%B9%97%E5%A0%B4/@33.7363156,132.4877213,17.78z/data=!4m5!3m4!1s0x3545615c8c65bf7f:0xb89272c1a705a33f!8m2!3d33.7366776!4d132.4878843
    B. https://www.google.com/maps/place/The+Flying+Saucer/@42.4043314,-86.2742418,15z/data=!4m5!3m4!1s0x0:0xe28f6108670216bc!8m2!3d42.4043316!4d-86.2742121
  3. Notice that the links are cut off after the colon and therefore don't hyperlink correctly.

Expected Result:

Links including colons should be correctly hyperlinked. In this example when clicked, should redirect to:
A. The cat island in Japan (and yes, it's an island full of cats)
B. The Flying Saucer in South Haven, MI

Actual Result:

Both links are not hyperlinked correctly and cut off after the colon.
image

Workaround:

User has to manually select the full link and paste it in the URL bar.

Platform:

Where is this issue occurring?

Web ✔️
iOS ✔️
Android ✔️
Desktop App ✔️
Mobile Web ✔️

Version Number: 1.0.79-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos:
Most Google Maps links are affected by this because they contain colons in the URL.
Please check the screenshot in Actual result.
I will try different links from other sites and, if I find more affected by this, will post the ones that have the same issue in comments.

Upwork Post: https://www.upwork.com/jobs/~017aff792b5b4f4a79

View all open jobs on Upwork


From @mallenexpensify https://expensify.slack.com/archives/C01GTK53T8Q/p1626278479245000

Links pasted into chats sometimes get cut off and the full link isn't properly hyperlinked in a message, especially for Google Maps links.

@MelvinBot
Copy link

Triggered auto assignment to @Gonals (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

@Gonals Gonals removed their assignment Jul 19, 2021
@Gonals Gonals added Improvement Item broken or needs improvement. Weekly KSv2 External Added to denote the issue can be worked on by a contributor labels Jul 19, 2021
@MelvinBot
Copy link

Triggered auto assignment to @trjExpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@MelvinBot MelvinBot removed the Weekly KSv2 label Jul 19, 2021
@Gonals Gonals added Weekly KSv2 and removed External Added to denote the issue can be worked on by a contributor Daily KSv2 labels Jul 19, 2021
@Gonals
Copy link
Contributor

Gonals commented Jul 19, 2021

We'll probably have to tweak the markdown a bit to get this to work correctly.
Sending to the pool!

@Gonals Gonals added the External Added to denote the issue can be worked on by a contributor label Jul 19, 2021
@MelvinBot MelvinBot added Daily KSv2 and removed Weekly KSv2 labels Jul 19, 2021
@trjExpensify trjExpensify changed the title Some links pasted into e.cash are broken and not properly hyperlinked Any links pasted into e.cash that includes a colon : break causing only the portion before the colon to be hyperlinked Jul 19, 2021
@trjExpensify
Copy link
Contributor

Looking at the screenshot, the common theme seems to be the colon : in the URL. Anything after that gets cut off. I tested that theory and it seems to hold up:

image

With that, I've updated the OP of the issue.

@MelvinBot MelvinBot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 19, 2021
@MelvinBot
Copy link

Triggered auto assignment to @marcaaron (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@parasharrajat
Copy link
Member

parasharrajat commented Jul 19, 2021

Proposal

I just adjusted the Path Regex to this

                                     Added this V 
const URL_PATH_REGEX = '(?:\\/[-\\w$@.&+!*"\'(),:=%~]*[-\\w~@:%)]|\\/)*';

And it is working fine and the whole test suite passed. It fixes the main issue.

There is another issue here #4105 (comment). which I will fix in the upcoming steps.

Explanation

We escape matching strings before applying scanning rules. Escaping converts a few chars as follows:

 var escapeMap = {
    '&': '&',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#x27;',
    '`': '&#x60;'
  };

Our Url regex didn't encounter escaped Symbols thus parsing is failing for '.

Fix

We have to update the URL regex to match the escaped Symbols as well.

For example, Path regex would be converted to

const URL_PATH_REGEX = '(?:\\/(?:[-\\w$@.&+!*"\'(),:=%~]|&amp;|&quot;|&#x27;)*[-\\w~@:%)]|\\/)*';

This fixes the other issue.

@trjExpensify
Copy link
Contributor

Interesting, what's the difference with what looks like a : in the list already? (right after the ?)

@mallenexpensify seems to have found this one as well, but the single quotation mark (') also seems included in the Path regex already? 🤔

image (86)

@parasharrajat
Copy link
Member

parasharrajat commented Jul 19, 2021

Ok, I found the issue with '. We are escaping the string before matching the URLs using Str.safeEscape. It escapes

  var escapeMap = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#x27;',
    '`': '&#x60;'
  };

So at the time of matching ' will be &#x27; that's why the match fails.

@rdjuric
Copy link
Contributor

rdjuric commented Jul 19, 2021

Interesting, what's the difference with what looks like a : in the list already? (right after the ?)

The : in ?: is part of the regex syntax, it's used to define a non-capturing group.

@parasharrajat
Copy link
Member

parasharrajat commented Jul 19, 2021

Again, I think escaping the URL with htmlentities will make it incorrect. so it's is better to unescape it before matching the URLs.

Edit:
We can't unescape it at this step, It will become impossible to escape it back after scanning or URLs. Escaping is needed for other selectors. If we escape it back then our converted markup will be escaped as well which is wrong.

So I have found the fix for that as well and we may have to update a few of regex to match the escaped version of

  var escapeMap = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#x27;',
    '`': '&#x60;'
  };

which will fix future issues. Updating proposal...

@trjExpensify trjExpensify removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 20, 2021
@parasharrajat
Copy link
Member

PR is up Expensify/expensify-common#396.

@MelvinBot
Copy link

@trjExpensify, @marcaaron Whoops! This issue is 2 days overdue. Let's get this updated quick!

@trjExpensify
Copy link
Contributor

This is done, closing it out. Reopen if I missed something, Gents!

@isagoico
Copy link
Author

isagoico commented Nov 4, 2021

Reopening this issue since @mallenexpensify was able to reproduce here https://expensify.slack.com/archives/C01GTK53T8Q/p1635954172411200

image

@isagoico isagoico reopened this Nov 4, 2021
@marcaaron marcaaron added the Weekly KSv2 label Nov 4, 2021
@MelvinBot MelvinBot removed the Overdue label Nov 4, 2021
@marcaaron marcaaron removed the Daily KSv2 label Nov 4, 2021
@mallenexpensify
Copy link
Contributor

I'm thinking, for issues like this that are likely to be recurring as we find variations, we shouldn't continue to reopen this one but open a new one each time. In the new issue, we can link back to this, gather examples then decide if/when we want a contributor to work on.

@marcaaron @trjExpensify @parasharrajat , y'all agree?

@trjExpensify
Copy link
Contributor

trjExpensify commented Nov 4, 2021 via email

@parasharrajat
Copy link
Member

parasharrajat commented Nov 4, 2021

I think parsing links is really giving us a hard time and we are hitting limitations of js regex. Should we reconsider md parser for links?

No preference @mallenexpensify

@isagoico
Copy link
Author

isagoico commented Nov 4, 2021

I agree with @mallenexpensify opening new tickets for other scenarios are easier to follow than reopening old ones. Let me know if we should start with this variation and create another ticket.

Also, able to reproduce with Matt's link
image

@marcaaron
Copy link
Contributor

I'm thinking, for issues like this that are likely to be recurring as we find variations, we shouldn't continue to reopen this one but open a new one each time. In the new issue, we can link back to this, gather examples then decide if/when we want a contributor to work on.

Sure. This link maybe looks like it's broken for another reason so we can close this.

@mallenexpensify
Copy link
Contributor

@isagoico can you create a brand new issue and include a link back to this? Thanks

@isagoico
Copy link
Author

isagoico commented Nov 4, 2021

Issue created here 🔝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engineering External Added to denote the issue can be worked on by a contributor Improvement Item broken or needs improvement. Weekly KSv2
Projects
None yet
Development

No branches or pull requests

8 participants