Skip to content

Fix: error from executing url regex#559

Merged
joelbettner merged 6 commits into
Expensify:mainfrom
eh2077:21266-try-catch-regex-execution-error
Jul 27, 2023
Merged

Fix: error from executing url regex#559
joelbettner merged 6 commits into
Expensify:mainfrom
eh2077:21266-try-catch-regex-execution-error

Conversation

@eh2077

@eh2077 eh2077 commented Jul 21, 2023

Copy link
Copy Markdown
Contributor

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

eh2077 commented Jul 21, 2023

Copy link
Copy Markdown
Contributor Author

@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?

@allroundexperts allroundexperts 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.

@eh2077 Can you please add tests for this?

@eh2077

eh2077 commented Jul 23, 2023

Copy link
Copy Markdown
Contributor Author

@allroundexperts Added test

@eh2077 eh2077 requested a review from allroundexperts July 24, 2023 01:25
Comment thread lib/ExpensiMark.d.ts
*/
containsNonPairTag(textToCheck: string): boolean;
extractLinksInMarkdownComment(comment: string): string[];
extractLinksInMarkdownComment(comment: string): string[] | undefined;

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.

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

@eh2077 eh2077 Jul 25, 2023

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.

@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

@allroundexperts allroundexperts 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.

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

@allroundexperts

Copy link
Copy Markdown
Contributor

Bump @eh2077

@eh2077

eh2077 commented Jul 25, 2023

Copy link
Copy Markdown
Contributor Author

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

@allroundexperts Added log messages.

@joelbettner joelbettner 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.

Only requesting a couple small changes to the error messages.

Comment thread lib/ExpensiMark.js Outdated
Comment thread lib/ExpensiMark.js Outdated

@allroundexperts allroundexperts 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.

Looking good!

@eh2077

eh2077 commented Jul 26, 2023

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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

eh2077 commented Jul 27, 2023

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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