Fix: regex execution Maximum regex stack depth reached error#23774
Conversation
|
@allroundexperts Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Bump @allroundexperts |
Reviewer Checklist
Screenshots/VideosWebScreen.Recording.2023-08-02.at.5.03.12.AM.movMobile Web - ChromeScreen.Recording.2023-08-02.at.5.04.20.AM.movMobile Web - SafariScreen.Recording.2023-08-02.at.5.05.21.AM.movDesktopScreen.Recording.2023-08-02.at.5.36.23.AM.moviOSScreen.Recording.2023-08-02.at.5.26.30.AM.movAndroidScreen.Recording.2023-08-02.at.5.27.01.AM.mov |
| const match = urlRegex.exec(href); | ||
| let match; | ||
| try { | ||
| if (!href.startsWith('mailto:')) { |
There was a problem hiding this comment.
Let's not add this condition. I think a try/catch is sufficient.
There was a problem hiding this comment.
I tried it but I tend to add this improvement for the following reasons.
- The slow regex execution takes some time to throw the error, which means the UI will be blocked during the time.
- As we render the long email as anchor tag, so every time we open a chat includes a long email will result in a brief moment of UI block. Given that I think it's better to skip executing the regex for email here.
There was a problem hiding this comment.
@eh2077 I think a better idea would be to apply the regex only if the length is less than a specific limit (set for each platform). What do you think?
There was a problem hiding this comment.
@allroundexperts I think early return for the email case is enough to avoid executing slow regex matching in this method. We avoid parsing long link causes error to anchor tag in method ExpensiMark.replace, which means we will only possibly have long email.
There was a problem hiding this comment.
Can we not add a similar condition (which we use while parsing long link) here as well?
There was a problem hiding this comment.
Can we not add a similar condition (which we use while parsing long link) here as well?
I think we can't because we don't do domain(TLD) checking when parsing email in ExpensiMark
There was a problem hiding this comment.
I might not be following you. Can you share a link of the condition you mentioned in your comment?
There was a problem hiding this comment.
Let me try to make it clear. There's no such similar condition for parsing link.
I mean only regex related to https://github.com/Expensify/expensify-common/blob/main/lib/Url.js causes the error and we catch it here https://github.com/Expensify/expensify-common/blob/56db2a0fc9df6b4270a99e4d3a9a7b0730ad2aa4/lib/ExpensiMark.js#L389. Note that the email regex https://github.com/Expensify/expensify-common/blob/56db2a0fc9df6b4270a99e4d3a9a7b0730ad2aa4/lib/CONST.jsx#L3 doesn't trigger the error(based testing), so ExpensiMark.replace will translate long email to anchor tag and this method will receive the long email of href parameter.
There was a problem hiding this comment.
Makes sense. Thanks!
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/bondydaa in version: 1.3.50-0 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 1.3.50-3 🚀
|
|
🚀 Deployed to staging by https://github.com/bondydaa in version: 1.3.51-0 🚀
|
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.51-2 🚀
|
Details
Fixed Issues
$ #21266
PROPOSAL: #21266 (comment)
Tests
<h1>headig</h1>is displayed as it isOffline tests
Same as tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Web
web.mov
Mobile Web - Chrome
mobile-chrome.mp4
Mobile Web - Safari
mobile-safari.mp4
Desktop
desktop.mov
iOS
safari.mp4
Android
android.mp4