Closed kbecciv closed 1 year ago
App throws 'No content to add' error if we send empty alias for email.
The root cause of this issue is that below markdown
[](test@gmail.com)
is translated into html
<a href="mailto:test@gmail.com"></a>
by applying email rule
{
name: 'email',
process: (textToProcess, replacement) => {
const regex = new RegExp(
`\\[([^[\\]]*)]\\(${CONST.REG_EXP.MARKDOWN_EMAIL}\\)`, 'gim'
);
return this.modifyTextForEmailLinks(regex, textToProcess, replacement);
},
replacement: (match, g1, g2) => `<a href="mailto:${g2}">${g1.trim()}</a>`,
}
The capturing group g1, ([^[\\]]*)
, is possible to be empty string and, in the replacement method, we didn't check if g1.trim()
is empty or not. So, we get anchor tag with empty text by apply the email rule.
The backend returns an error when we try to save html <a href="mailto:test@gmail.com"></a>
to the backend. The error returned by backend is
I think the error from backend makes sense because the backend needs to convert html
<a href="mailto:test@gmail.com"></a>
to text(aka message[0].text
) which shouldn't be empty.
So the root cause of this issue is that email rule doesn't avoid creating anchor tag with empty text.
To fix this issue, we can skip creating anchor tag with empty text.
To achieve this, we can change the replacement method of email rule from
replacement: (match, g1, g2) => `<a href="mailto:${g2}">${g1.trim()}</a>`,
to
// skip rendering if g1.trim() is empty
replacement: (match, g1, g2) => (!g1.trim() ? match : `<a href="mailto:${g2}">${g1.trim()}</a>`),
Below is the demo video of the solution
https://github.com/Expensify/App/assets/117511920/4fc47889-2aa8-4e10-93eb-4d9eb94d037a
We can also add a negative lookahead group at the beginning of the regex to skip matching email markdown syntax starts with \[\s*\]
.
To achieve it, we can change the regex
`\\[([^[\\]]*)]\\(${CONST.REG_EXP.MARKDOWN_EMAIL}\\)`, 'gim'
to
`(?!\\[\\s*\\])\\[([^[\\]]*)]\\(${CONST.REG_EXP.MARKDOWN_EMAIL}\\)`, 'gim'
The negative lookahead group (?!\[\s*\])
will be able to skip matching linkText includes only whitespaces(including linebreaks because the regex has multiple line flag m
). See below demo video including more test cases.
https://github.com/Expensify/App/assets/117511920/d20de407-1cc7-4990-95e8-fa653b25b9c2
Triggered auto assignment to @laurenreidexpensify (Bug
), see https://stackoverflow.com/c/expensify/questions/14418 for more details.
Platforms
in OP are β
)Checking something internally here https://expensify.slack.com/archives/C01SKUP7QR0/p1687437975259329 about this
Job added to Upwork: https://www.upwork.com/jobs/~012e72288a82e6fae6
Current assignee @laurenreidexpensify is eligible for the External assigner, not assigning anyone new.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External
)
@eh2077 Proposal looks good to me. But I am not sure if that is the expected behavior. I am shocked that this issue existed. I am unable to remember how it used to behave a few months back.
@laurenreidexpensify Do you think the video should be expected behavior?
App throws 'No content to add' error if we send empty alias for email.
As @eh2077 's analyzed, when backend parse empty anchor tag, return error.
Simple solution is that we would not allow conversion into empty anchor tag. To do that, we can tweak a bit on Regex pattern as following.
Just simply add (?!\[[\s]*\]) at the beginning of email rule's regex pattern.
Test result is same as @eh2077 's proposal
N/A
@YacineF0001 Thanks for tagging me in your proposal. But I think our solutions are different for test case like
[ ](test@gmail.com)
Below is the demo video for two test cases
[](test@gmail.com)
[ ](test@gmail.com)
https://github.com/Expensify/App/assets/117511920/3aaeafeb-34be-4d16-8ba0-83c4cc4c61f3
I think the App prefers to keep the user input as it is. So, in the editing mode, we display the original input.
@laurenreidexpensify Happy to hear your thoughts on the expected behaviour.
cc @parasharrajat
@eh2077 Thanks for your pointing out. it can be also done with Regex. Just add (?!\[[ ]*\]) at the beginning of pattern.
@parasharrajat My proposal updated
Updated to add an alternative regex based method and included a demo video covers more test cases.
cc @parasharrajat
@eh2077 good catching about linebreak case. but don't add it as your solution with just adding a case on my solution.
Proposal updated to add linebreak case cc @parasharrajat
@eh2077 Thanks for your pointing out. it can be also done with Regex.
Just add (?!\[[ ]*\]) at the beginning of pattern.
@parasharrajat My proposal updated
@YacineF0001 I think your method only fixes the effects and not the root cause. The method I suggested to handle all white spaces fixes the root causes. That's the essential.
@eh2077 you just added a case with '\s' instead of ' ' on my regex. i just missed linebreak case your original solution is also working for this issue, so let's wait for @parasharrajat 's review on your original one and my regex solution
@eh2077 you just added a case with '\s' instead of ' ' on my regex.
I'm afraid I can't agree on it. According to timeline, I first came up the regex solution to solve the root cause of all whitespaces, which is essential to fix the root cause of the issue.
so let's wait for @parasharrajat 's review on your original one and my regex solution
I think the C+ team will review it following the contribution guides here
Expensify reviews all solution proposals on a first come first serve basis. If you see other contributors have already proposed a solution, you can still provide a solution proposal and we will review it. We look for the earliest provided, best proposed solution that addresses the job.
I fixed unit test cases for the change of regex pattern. and added test case with linebreak. Proposal updated cc @parasharrajat
I think the C+ team will review it following the contribution guides here
From now on, My last updated proposal would be more improved.
@parasharrajat yeah I agree that the expected behaviour should be to display the broken link as normal text rather removing it and throwing an error. So exactly as you have it in the video.
Hey everyone. Thanks for the updates. I will review them as soon as possible.
It's definitely a tough call. I saw the timeline of all the proposal updates. It seems the @eh2077 came first with the better regex. Although @eh2077's main solution is also working, I like the idea of updating the regex.
It seems that @YacineF0001 spark the idea of regex which helped @eh2077 come up with an alternative approach but @eh2077 also shared feedback which helped reach the final proposal of @YacineF0001.
In these situations, we choose a better solution over others. This is part of OSS that a solution sparks ideas in other contributors.
As @eh2077 came up first with a better approach. I think we should go with their proposal's alternative method.
Thanks @YacineF0001 for your proposal. You seem to be a new contributor to the project. Happy to have you. There are many more opportunities waiting. I am sure you will soon land one.
:ribbon: :eyes: :ribbon: C+ reviewed
Triggered auto assignment to @Gonals, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@parasharrajat Thanks for your review. I hope you take care of my latest proposal. I addressed about auto-test cases to be fixed and added more. Without it, i think it can't be perfect proposal.
I think @eh2077 's proposal is imperfect, because he didn't address following issue on unit test. @parasharrajat Do you think it's can be ignored ?
I will update you tomorrow.
@parasharrajat Thanks for reviewing proposals.
I'm open to share the bounty with @YacineF0001 , like 50/50. I'd also suggest to let @YacineF0001 make the PR which should be his first contribution to the App! If speed bonus is qualified, then it will be compensated to him only. Hope team will take this into consideration.
π£ It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? πΈ
I am fine with it @eh2077. What do you say @YacineF0001?
Bump @Gonals
@parasharrajat I agree with this, and appreciate @eh2077 's kindness and professional behavior.
π£ @parasharrajat You have been assigned to this job! Please apply to this job in Upwork here and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review π§βπ» Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs! Keep in mind: Code of Conduct | Contributing π
π£ @eh2077 You have been assigned to this job! Please apply to this job in Upwork here and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review π§βπ» Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs! Keep in mind: Code of Conduct | Contributing π
π£ @dhanashree! π£ Hey, it seems we donβt have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
The BZ member will need to manually hire dhanashree for this role Reporter. Please store your Upwork details and apply to our Upwork job so this process is automatic in the future!
@parasharrajat Thanks for reviewing proposals.
I'm open to share the bounty with @YacineF0001 , like 50/50. I'd also suggest to let @YacineF0001 make the PR which should be his first contribution to the App! If speed bonus is qualified, then it will be compensated to him only. Hope team will take this into consideration.
@laurenreidexpensify could i apply to this job ?
This is still awaiting Engineer review @laurenreidexpensify
@parasharrajat is tehre something specific that requires technical review? we updated the process in the past couple of weeks, so engineering review is only required on the PR or any technical conversation in the issue, so if you're happy with the solution and the team sharing the bounty, then SGTM and we can move to PR?
No, Engineer needs to approve the C+ decision on issue before moving to the PR. @laurenreidexpensify
Anyways, I need approval on https://github.com/Expensify/App/issues/21234#issuecomment-1610433760 before moving forward. And if we agree, let's reassign the issue to the right contributor.
I am fine with it @eh2077. What do you say @YacineF0001?
Bump @Gonals
I was OOO until today, but I agree with this too π
π£ @parasharrajat You have been assigned to this job! Please apply to this job in Upwork here and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review π§βπ» Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs! Keep in mind: Code of Conduct | Contributing π
π£ @YacineF0001 You have been assigned to this job! Please apply to this job in Upwork here and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review π§βπ» Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs! Keep in mind: Code of Conduct | Contributing π
The BZ member will need to manually hire dhanashree for this role Reporter. Please store your Upwork details and apply to our Upwork job so this process is automatic in the future!
@Gonals @parasharrajat Thank you for assignment. Unfortunately, I can't apply for the job, because my Upwork account was suspended a few days ago. Is there any alternative ? Is it possible to apply there with my friend's account ?
@YacineF0001 I think you can start to prepare the PR. Usually you don't have to apply the job to be allowed to submit the PR. You can also apply the job when payment is due, so you'll have time to handle your Upwork account issue during that time.
Thanks for your advice. But not sure if it can be resolved. Tried something for a few days, but no response. I hope you make PR for this issue. I feel that you are eligible to do that. I will appreciate if you can share me 50% of bounty after payment is proceeded.
@YacineF0001 Can you share your Upwork profile link?
already registered here. https://www.upwork.com/freelancers/~01cb7dfbaec5a6c8d6
Unfortunately, that is a problem. @laurenreidexpensify Can you please look into this?
@parasharrajat Should I make the PR to move the issue forward quicker as suggested by @YacineF0001 's https://github.com/Expensify/App/issues/21234#issuecomment-1619379253 ?
If you havenβt already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Action Performed:
[](google.com)
[](test@test.com)
Expected Result:
App should handle empty alias for email in similar way like it does for link
Actual Result:
App throws 'No content to add' error for email with empty alias
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Version Number: 1.3.30.0
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
https://github.com/Expensify/App/assets/93399543/3efe4b24-22e0-47e5-9758-5bae899a4dac
https://github.com/Expensify/App/assets/93399543/b68bed52-6612-4012-9223-1ffaf656b18d
Expensify/Expensify Issue URL:
Issue reported by: @dhanashree-sawant
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1686755882619169
View all open jobs on GitHub
Upwork Automation - Do Not Edit