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

[$500] Markdown - Sending a message with two ">" characters replaces one ">" with a whitespace #34142

Closed
1 of 6 tasks
lanitochka17 opened this issue Jan 9, 2024 · 16 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@lanitochka17
Copy link

lanitochka17 commented Jan 9, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 1.4.23-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
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Open a conversation
  2. Send a quote markdown message with one ">" before a text
  3. Send another quote markdown message with two ">" characters before a text
  4. Click on edit on the message sent on step 2
  5. Click on edit on the message sent on step 3 and compare it with step 4's result

Expected Result:

One of the ">" characters should not be replaced with a white space

Actual Result:

One of the ">" characters becomes replaced by a whitespace

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • Windows: Chrome
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6336731_1704809430448.quote.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~010d9e66996671f8b8
  • Upwork Job ID: 1744725330977787904
  • Last Price Increase: 2024-01-23
@lanitochka17 lanitochka17 added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jan 9, 2024
@melvin-bot melvin-bot bot changed the title Markdown - Sending a message with two ">" characters replaces one ">" with a whitespace [$500] Markdown - Sending a message with two ">" characters replaces one ">" with a whitespace Jan 9, 2024
Copy link

melvin-bot bot commented Jan 9, 2024

Job added to Upwork: https://www.upwork.com/jobs/~010d9e66996671f8b8

Copy link

melvin-bot bot commented Jan 9, 2024

Triggered auto assignment to @mallenexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 9, 2024
Copy link

melvin-bot bot commented Jan 9, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @ntdiary (External)

@ghost
Copy link

ghost commented Jan 9, 2024

I am interested to work on it

@vadymbokatov
Copy link
Contributor

vadymbokatov commented Jan 9, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

When sending a message containing double ">" in any conversations, the second ">" gets replaced by an empty spaced.

What is the root cause of that problem?

The problem is comming from the expensify-common package. More specifically, the ExpensiMark component. While trying to find the root cause, I came across this function:

function getParsedComment(text: string): string {
    const parser = new ExpensiMark();
    return text.length <= CONST.MAX_MARKUP_LENGTH ? parser.replace(text) : lodashEscape(text);
}

Located in /src/libs/ReportUtils.ts. It is using the parser.replace method which is coming from import ExpensiMark from 'expensify-common/lib/ExpensiMark'; and is causing this issue. I will update my proposal with more details.

What changes do you think we should make in order to solve the problem?

The parser.replace method from ExpensiMark package should be updated as such to prevent removing the second ">".

Update:

More specifically, by replacing the following regex inside the ExpensiMark package, I managed to fix this issue:

// Old Regex
/^&gt;( )?/gm

// Suggested Regex
/^(&gt;){,1}( )?/gm

This way, we assure that the match happens only once and both of the $gt; texts don't get replaced.

What alternative solutions did you explore? (Optional)

None.

@vadymbokatov
Copy link
Contributor

vadymbokatov commented Jan 9, 2024

Proposal

Updated

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Sending quote markdown with double >> will not show the second >

What is the root cause of that problem?

When we are creating a message with markdown, it will call the ExpensiMark parser replace function. For quote, there are 2 cases, keeping any whitespace or trimming all whitespace.
https://github.com/Expensify/expensify-common/blob/23c34c6d37d8b46a3d0a1fd287da4551416bc9dd/lib/ExpensiMark.js#L209-L212

By default, adding a new comment will call the parser replace with trimming all whitespace. If we trim all whitespace, it will call modifyTextForQuote which will then call formatTextForQuote. In formatTextForQuote, we want to remove the first > for each line and trim it. This logic was added in Expensify/expensify-common#521
https://github.com/Expensify/expensify-common/blob/23c34c6d37d8b46a3d0a1fd287da4551416bc9dd/lib/ExpensiMark.js#L814-L819

If we send > >a, the result will be >a.

This worked fine before, but then, it will continue by calling the rules replacement logic that will also remove the > which was added by this later PR. This PR is the one that added whether we want to keep the whitespace or not.
https://github.com/Expensify/expensify-common/blob/23c34c6d37d8b46a3d0a1fd287da4551416bc9dd/lib/ExpensiMark.js#L214-L224

So the final message becomes a and wrapped with <blockquote> tag.

In summary, we have 2 cases of quote, keeping the whitespace or trimming it. Both cases will call the replacement logic which will remove the >, but for the trim case, we have another logic to remove > too (before calling the replacement logic), so the > is removed twice.

What changes do you think we should make in order to solve the problem?

To fix this, we should have the > removing logic in one place and that is in the replacement function.

  1. In formatTextForQuote, delete the > removing logic and pass the text unmodified to the replacement logic
    https://github.com/Expensify/expensify-common/blob/23c34c6d37d8b46a3d0a1fd287da4551416bc9dd/lib/ExpensiMark.js#L813-L820
    This will ensure the > removing logic only happens once.
  2. In the replacement logic, we will set isStartingWithSpace to true only if shouldKeepRawInput is true, and also we want to trim the textToReplace if shouldKeepRawInput is true
    https://github.com/Expensify/expensify-common/blob/23c34c6d37d8b46a3d0a1fd287da4551416bc9dd/lib/ExpensiMark.js#L217-L223
let textToReplace = g1.replace(/^&gt;( )?/gm, (match, g2) => {
    isStartingWithSpace = !!g2 && shouldKeepRawInput;
    return '';
});
if (!shouldKeepRawInput) {
    textToReplace = textToReplace.trim()
}

We need to trim it here because we already remove the > removing logic from formatTextForQuote.

@mallenexpensify
Copy link
Contributor

Checking on summin' internally
https://expensify.slack.com/archives/C01SKUP7QR0/p1704850748783939

@melvin-bot melvin-bot bot added the Overdue label Jan 12, 2024
Copy link

melvin-bot bot commented Jan 15, 2024

@ntdiary, @mallenexpensify Eep! 4 days overdue now. Issues have feelings too...

@suneox
Copy link
Contributor

suneox commented Jan 15, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

Markdown - Sending a message with two ">" characters replaces one ">" with a whitespace

What is the root cause of that problem?

Before submit message we have getParsedComment, and this function is using ExpensiMark to replace the current message to markdown at this line
The rule for quote is replace &gt; 2 times on both method process and replacement.
At step process when formatTextForQuote we remove 4 first characters &gt; at this line after that we continue to excute replacement function has provide by quote rule in this function we continue to replace &gt; at this line

What changes do you think we should make in order to solve the problem?

At function formatTextForQuote we should only repare the content for replacement function so we will remove logic to remove 4 first characters substr(4) at this line
change to

let textToFormat = textToCheck.split('\n').map(row => row.trim()).join('\n');

What alternative solutions did you explore? (Optional)

@mallenexpensify
Copy link
Contributor

Checking a different spot internally to see what we want to do here
https://expensify.slack.com/archives/C066HJM2CAZ/p1705366484642439

@melvin-bot melvin-bot bot removed the Overdue label Jan 16, 2024
Copy link

melvin-bot bot commented Jan 16, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Jan 18, 2024
Copy link

melvin-bot bot commented Jan 19, 2024

@ntdiary, @mallenexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!

@ntdiary
Copy link
Contributor

ntdiary commented Jan 20, 2024

Checking a different spot internally to see what we want to do here https://expensify.slack.com/archives/C066HJM2CAZ/p1705366484642439

Waiting for the result of the internal discussion.

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Jan 20, 2024
Copy link

melvin-bot bot commented Jan 23, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@mallenexpensify
Copy link
Contributor

Going to close for now since it's a tiny bug and not directly related to a VIP or wave project on our roadmap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
None yet
Development

No branches or pull requests

6 participants