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: export link regex for use in edit message #540

Merged
merged 7 commits into from
May 23, 2023

Conversation

s-alves10
Copy link
Contributor

Fixed Issues

$ Expensify/App#18911

Tests

  1. What unit/integration tests cover your change? What autoQA tests cover your change?
    ExpensiMark-HTML-test.js. Nothing added because there is no regex change.
  2. What tests did you perform that validates your changed worked?
    Make sure that all unit-tests are passed.

QA

  1. What does QA need to do to validate your changes?
    This PR has no regex change. Can verify if all unit-tests are passed.
  2. What areas to they need to test for regressions?
    Nothing.

@s-alves10 s-alves10 requested a review from a team as a code owner May 19, 2023 21:14
@github-actions
Copy link

github-actions bot commented May 19, 2023

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

@melvin-bot melvin-bot bot requested review from MariaHCD and removed request for a team May 19, 2023 21:15
@s-alves10
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@s-alves10
Copy link
Contributor Author

recheck

@s-alves10
Copy link
Contributor Author

@MariaHCD
Please review this PR asap. This PR needs to be merged in order to complete this PR for issue 18911

@aimane-chnaif
Copy link
Contributor

@neil-marcellini and I will be reviewing this.

Copy link
Contributor

@aimane-chnaif aimane-chnaif left a comment

Choose a reason for hiding this comment

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

@s-alves10 your current change itself looks good.
But how will you solve this regression - Expensify/App#18911 (comment)?

@s-alves10
Copy link
Contributor Author

s-alves10 commented May 19, 2023

@s-alves10 your current change itself looks good. But how will you solve this regression - Expensify/App#18911 (comment)?

@aimane-chnaif
We need to share the same regex in editing comment with expensify-common. When we send the comment, we escape the string first and pass the rules. I did the same. When checking if a link exists, escape the editing comment and run the regex. This works fine.

image

result
18911.mp4

@@ -3,6 +3,8 @@ import Str from './str';
import {MARKDOWN_URL_REGEX, LOOSE_URL_REGEX, URL_REGEX} from './Url';
import {CONST} from './CONST';

const MARKDOWN_LINK_REGEX = `\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this to Url.js

Copy link
Contributor Author

@s-alves10 s-alves10 May 22, 2023

Choose a reason for hiding this comment

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

@aimane-chnaif
I intentionally placed this constant in ExpensiMark.js. This is not the URL regex, is the regex for parsing markdown URL.
Should I still move this regex to Url.js?

Copy link
Contributor

Choose a reason for hiding this comment

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

Still I suggest Url.js.
There's no non-default exported const or function defined in ExpensiMark.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aimane-chnaif
Copy link
Contributor

@s-alves10 your current change itself looks good. But how will you solve this regression - Expensify/App#18911 (comment)?

@aimane-chnaif We need to share the same regex in editing comment with expensify-common. When we send the comment, we escape the string first and pass the rules. I did the same. When checking if a link exists, escape the editing comment and run the regex. This works fine.

image

result

can you explain why escape should work?

@s-alves10
Copy link
Contributor Author

s-alves10 commented May 22, 2023

can you explain why escape should work?

@aimane-chnaif
When we escape the string, < and > are escaped to &lt; and &gt;. That's the reason.
And the another reason I did so is to keep the parsing logic same between sending and editing comment.

aimane-chnaif
aimane-chnaif previously approved these changes May 22, 2023
Copy link
Contributor

@aimane-chnaif aimane-chnaif left a comment

Choose a reason for hiding this comment

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

@s-alves10
Copy link
Contributor Author

s-alves10 commented May 22, 2023

@neil-marcellini @MariaHCD
This PR needs to be merged in order to complete this PR for issue 18911.

Will you review this PR?

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Sorry to keep changing my recommendations, I want to make sure this works as well as possible and stays consistent in the future.

How about we just move these two functions from App to expensify-common, then we can simply use them in App?

lib/Url.js Outdated
@@ -16,6 +16,7 @@ const LOOSE_URL_REGEX = `((${LOOSE_URL_WEBSITE_REGEX})${URL_PATH_REGEX}(?:${URL_


const MARKDOWN_URL_REGEX = `(${LOOSE_URL_REGEX}|${URL_REGEX})`;
const MARKDOWN_LINK_REGEX = `\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem relevant here because it is about links, not just URLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to ExpensiMark.js

`\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`,
'gi',
);
const regex = new RegExp(MARKDOWN_LINK_REGEX, 'gi');
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's we're building a regex with the 'gi' flags, but in App we're using the 'gm' flags. That's an example of an inconsistency with this approach.

Copy link
Contributor Author

@s-alves10 s-alves10 May 22, 2023

Choose a reason for hiding this comment

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

@neil-marcellini
I think gi flag is intentional not to parse multiline link. In App, we'll be using gi flags as well.
Actually, ExpensiMark uses this flag for both link and autolink at the moment.

@aimane-chnaif
Copy link
Contributor

@neil-marcellini ok, I don't mind about that refactoring. But how about the main solution?
Do you think escaping html is fine approach?

@s-alves10
Copy link
Contributor Author

s-alves10 commented May 23, 2023

Sorry to keep changing my recommendations, I want to make sure this works as well as possible and stays consistent in the future.

How about we just move these two functions from App to expensify-common, then we can simply use them in App?

@neil-marcellini
I'm sorry but I wasn't able to find any reason to move those functions to expensify-common. Will you tell me the reason why it's better to move those functions here?
And please let me know where you suggest to move those functions to.

@MariaHCD
Copy link
Contributor

Looks like @neil-marcellini has got this covered, un-assigning myself as reviewer.

@MariaHCD MariaHCD removed their request for review May 23, 2023 08:11
@s-alves10
Copy link
Contributor Author

@neil-marcellini
Please let me know your thoughts about my comments. I'll make changes according to you.
I hope make this PR merged asap.

@neil-marcellini
Copy link
Contributor

@s-alves10 I will look at this within the next hour. Please feel free to message me on NewDot if you want to chat quickly.

@s-alves10
Copy link
Contributor Author

s-alves10 commented May 23, 2023

@s-alves10 I will look at this within the next hour. Please feel free to message me on NewDot if you want to chat quickly.

Please let me know your address on NewDot

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

We started a group DM in NewDot to discuss.

aimane-chnaif
aimane-chnaif previously approved these changes May 23, 2023
Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Looking pretty good!

lib/ExpensiMark.js Outdated Show resolved Hide resolved
lib/ExpensiMark.js Outdated Show resolved Hide resolved
lib/ExpensiMark.js Show resolved Hide resolved
lib/ExpensiMark.js Outdated Show resolved Hide resolved
Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Nice, good to go!

@@ -3,7 +3,7 @@ import Str from './str';
import {MARKDOWN_URL_REGEX, LOOSE_URL_REGEX, URL_REGEX} from './Url';
import {CONST} from './CONST';

const MARKDOWN_LINK_REGEX = `\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`;
const MARKDOWN_LINK_REGEX = new RegExp(`\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, 'gi');
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Add a 'P' to the end of the name so we know it's not just a string MARKDOWN_LINK_REGEXP. Idk, maybe too subtle.

@neil-marcellini neil-marcellini merged commit 68abe48 into Expensify:main May 23, 2023
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.

5 participants