-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: regex execution Maximum regex stack depth reached error #23774
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not add this condition. I think a try/catch
is sufficient.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not add a similar condition (which we use while parsing long link) here as well?
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks!
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!
✋ 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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.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