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: error from executing url regex #559

Merged

Conversation

eh2077
Copy link
Contributor

@eh2077 eh2077 commented Jul 21, 2023

Fixed Issues

$ Expensify/App#21266

Tests

  1. Open iOS App and go to a chat
  2. Add following comment
www.asjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfidekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdicdjejajasjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfisjksksjsjssskssjskskssksksksksskdkddkddkdksskskdkdkdksskskskdkdkdkdkekeekdkddenejeodxkdndekkdjddkeemdjxkdenendkdjddekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdicdjejajasjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfidekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdi.com
  1. Verify App doesn’t crash after adding the comment
  2. Click to edit the link and replace the link to
www.asjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfidekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdicdjejajasjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfisjksksjsjssskssjskskssksksksksskdkddkddkdksskskdkdkdksskskskdkdkdkdkekeekdkddenejeodxkdndekkdjddkeemdjxkdenendkdjddekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdicdjejajasjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfidekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdi.org
  1. Verify the link is changed and the App doesn’t crash

QA

Same as test

@eh2077 eh2077 requested a review from a team as a code owner July 21, 2023 06:42
@melvin-bot melvin-bot bot requested review from joelbettner and removed request for a team July 21, 2023 06:42
@eh2077
Copy link
Contributor Author

eh2077 commented Jul 21, 2023

@allroundexperts Should I move methods Url.getURLObject and ValidationUtils.isValidWebsite from App to this repo? Or just add try/catch to handle them in the App repo?

Copy link
Contributor

@allroundexperts allroundexperts left a comment

Choose a reason for hiding this comment

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

@eh2077 Can you please add tests for this?

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 23, 2023

@allroundexperts Added test

@eh2077 eh2077 requested a review from allroundexperts July 24, 2023 01:25
@@ -86,7 +86,7 @@ export default class ExpensiMark {
* @param textToCheck - Text to check
*/
containsNonPairTag(textToCheck: string): boolean;
extractLinksInMarkdownComment(comment: string): string[];
extractLinksInMarkdownComment(comment: string): string[] | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of undefined, lets return [] as it was doing previously?

Copy link
Contributor Author

@eh2077 eh2077 Jul 25, 2023

Choose a reason for hiding this comment

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

@allroundexperts I tend to stick with return undefined when exception occurs for the following reason. This method currently is only used by method getRemovedMarkdownLinks which needs to call this method twice to do diff to get the removed links. My point here is to let method getRemovedMarkdownLinks return empty array [] if any of the two links array is undefined, which means don't remove links if any exception occurs. Does it make sense to you?

Let's say, there's a new comment with multiple links but one of them causes regex execution error, in this case, we return undefined to skip removing any links. If we return [] for the new comment, then method getRemovedMarkdownLinks will remove all links.

New comment
asjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfidekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdicdjejajasjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfisjksksjsjssskssjskskssksksksksskdkddkddkdksskskdkdkdksskskskdkdkdkdkekeekdkddenejeodxkdndekkdjddkeemdjxkdenendkdjddekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdicdjejajasjjssjdjdjdjdjdjjeiwiwiwowkdjdjdieikdjfidekjcjdkekejdcjdkeekcjcdidjjcdkekdiccjdkejdjcjxisdjjdkedncicdjejejcckdsijcjdsodjcicdkejdi.cdjd
www.google.com
www.expensify.com
Old comment
www.google.com
www.expensify.com

Copy link
Contributor

@allroundexperts allroundexperts left a comment

Choose a reason for hiding this comment

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

I think it will also be good to log the failure for tracking purposes!

@allroundexperts
Copy link
Contributor

Bump @eh2077

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 25, 2023

I think it will also be good to log the failure for tracking purposes!

@allroundexperts Added log messages.

Copy link
Contributor

@joelbettner joelbettner left a comment

Choose a reason for hiding this comment

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

Only requesting a couple small changes to the error messages.

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

@allroundexperts allroundexperts left a comment

Choose a reason for hiding this comment

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

Looking good!

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 26, 2023

@allroundexperts I found an error when sending log to backend using Logger setting from this repo https://github.com/Expensify/expensify-common/blob/main/lib/Log.jsx

It looks like that the App doesn't include the jQuery in the build.

The logger from App repo seems working well https://github.com/Expensify/App/blob/main/src/libs/Log.js

Any suggestions on how to fix this issue?

cc @joelbettner

@allroundexperts
Copy link
Contributor

@eh2077 But we're adding jquery in our dependency list as seen here.

If this is something that can be fixed quickly, then lets try to address that within this PR. If not, then we can comment out the log statements and create a new issue for fixing this.

@joelbettner Let us know your thoughts.

@eh2077
Copy link
Contributor Author

eh2077 commented Jul 27, 2023

@allroundexperts I dug the logging error stack and I feel it's a bit tricky. I also found that jQuery may not be able to use in native platform. So I think we can use console.warn to avoid using the logger.

@eh2077 eh2077 requested a review from allroundexperts July 27, 2023 06:57
@allroundexperts
Copy link
Contributor

All yours @joelbettner!

@joelbettner joelbettner merged commit 9940dd1 into Expensify:main Jul 27, 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.

3 participants