-
Notifications
You must be signed in to change notification settings - Fork 135
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: add support for localhost urls in markdown #535
Conversation
@Santhosh-Sellavel any chance you can test this in App? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @allroundexperts looking good, is there an easy way to test this with the App before merging?
lib/Url.js
Outdated
const LOOSE_URL_REGEX = `(${LOOSE_URL_WEBSITE_REGEX}${URL_PATH_REGEX}(?:${URL_PARAM_REGEX}|${URL_FRAGMENT_REGEX})*)`; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include the LOOSE_URL_REGEX along with the exported URL_REGEX
as OR from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Santhosh-Sellavel Of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. But we'll still need to import the both as well because of this condition.
@mountiny I've been testing it by applying the changes directly in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests look good but I'm a bit confused about the regex. I think you should also include test steps in App.
@@ -11,6 +11,12 @@ const URL_REGEX = `(${URL_WEBSITE_REGEX}${URL_PATH_REGEX}(?:${URL_PARAM_REGEX}|$ | |||
|
|||
const URL_REGEX_WITH_REQUIRED_PROTOCOL = URL_REGEX.replace(`${URL_PROTOCOL_REGEX}?`, URL_PROTOCOL_REGEX); | |||
|
|||
const LOOSE_URL_WEBSITE_REGEX = `${URL_PROTOCOL_REGEX}([-\\w]+(\\.[-\\w]+)*)(?:\\:${ALLOWED_PORTS}|\\b|(?=_))`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this chunk of the regex please? How did you come up with it and what is it supposed to do?
([-\\w]+(\\.[-\\w]+)*)
My understanding is that it should match the domain name, however it isn't explained that way on regex101. Maybe I'm missing something...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neil-marcellini You need to replace the \\
with \
when testing it on regex101
. The mentioned regex matches any word character along with a hyphen followed by an option .
and any word character (hyphens included) zero or more times. This is added to cover domain names on local machines. These could be: localhost
, a.b.c
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah got it thanks!
You need to replace the
\\
with\
when testing it onregex101
Can you explain why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure but I think it might be due to the fact that we're having the regex in string form in our code and then we're converting it using new Regex
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@allroundexperts could you show tests with the App please?
@mountiny Sure. |
@@ -454,7 +454,7 @@ export default class ExpensiMark { | |||
if (abort) { | |||
replacedText = replacedText.concat(textToCheck.substr(match.index, (match[0].length))); | |||
} else { | |||
const urlRegex = new RegExp(`^${URL_REGEX}$`, 'i'); | |||
const urlRegex = new RegExp(`^${LOOSE_URL_REGEX}$|^${URL_REGEX}$`, 'i'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use MARKDOWN_URL_REGEX here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Santhosh-Sellavel We can't use it because ^${LOOSE_URL_REGEX}$|^${URL_REGEX}$
is different from ^${LOOSE_URL_REGEX}|${URL_REGEX}$
. We want it to EITHER start and end with loose url regex OR start and end with URL_REGEX
.
13ea2b4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, tests well. Will continue on App PR thanks!
bump @mountiny or @neil-marcellini |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks everyone!
@@ -11,6 +11,12 @@ const URL_REGEX = `((${URL_WEBSITE_REGEX})${URL_PATH_REGEX}(?:${URL_PARAM_REGEX} | |||
|
|||
const URL_REGEX_WITH_REQUIRED_PROTOCOL = URL_REGEX.replace(`${URL_PROTOCOL_REGEX}?`, URL_PROTOCOL_REGEX); | |||
|
|||
const LOOSE_URL_WEBSITE_REGEX = `${URL_PROTOCOL_REGEX}([-\\w]+(\\.[-\\w]+)*)(?:\\:${ALLOWED_PORTS}|\\b|(?=_))`; | |||
const LOOSE_URL_REGEX = `((${LOOSE_URL_WEBSITE_REGEX})${URL_PATH_REGEX}(?:${URL_PARAM_REGEX}|${URL_FRAGMENT_REGEX})*)`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We allowed the URL to start by hyphen
which is not allowed according to the RFC1034. This caused Expensify/App#27080
This PR adds support for auto linking of local urls like
http://my-localhost
,http://localhost:3000
Fixed Issues
$ Expensify/App#17828
Tests
What unit/integration tests cover your change? What autoQA tests cover your change?
URL-test
,ExpensiMark-HTML-test
andExpensiMark-HTMLToText-test
What tests did you perform that validates your changed worked?
Added new test cases that auto link local urls.
QA
What does QA need to do to validate your changes?
Run the new test cases
What areas to they need to test for regressions?
Check if urls are getting auto linked correctly