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

[Hold #44262] [$250] Chat-Quote Markdown without space is applied as a quote in sent chat but not in compose box #43323

Closed
2 of 6 tasks
kavimuru opened this issue Jun 7, 2024 · 27 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. 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 Monthly KSv2 Reviewing Has a PR in review

Comments

@kavimuru
Copy link

kavimuru commented Jun 7, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.80-14
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. Navigate to any chat
  2. Type >hey (There shouldn't be a space between ">" and "hey")
  3. In a second line type > hey (with a space between ">" and "hey")
  4. In a third line line type > hey (with two spaces between ">" and "hey")
  5. Send the message

Expected Result:

The first line shouldn't be rendered as a quote markdown. It should be rendered as '>hey'

Actual Result:

The first line without space is rendered as a quote.

Workaround:

unknown

Platforms:

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

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

Screenshots/Videos

Bug6505597_1717793936542.2024-06-07_23_11_32.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01352a9a30d580bacb
  • Upwork Job ID: 1800195684107077831
  • Last Price Increase: 2024-06-17
Issue OwnerCurrent Issue Owner: @sobitneupane
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jun 7, 2024
Copy link

melvin-bot bot commented Jun 7, 2024

Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@kavimuru
Copy link
Author

kavimuru commented Jun 7, 2024

@trjExpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors.

@kavimuru
Copy link
Author

kavimuru commented Jun 7, 2024

We think this bug might be related to #vip-vsb

@devguest07
Copy link
Contributor

devguest07 commented Jun 10, 2024

##Proposal

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

Chat-Quote Markdown without space is applied as a quote in sent chat but not in the compose box.

What is the root cause of that problem?

When typing in the composer, the text is saved to the database (Onyx) with the getParsedComment function.

getParsedComment uses a parser from expensify-common that converts markdown into HTML.

The issue lies in the getParsedComment function performing incorrect transformations. For example, a text like >w/n> w should be transformed to:

>w
<blockquote>w</blockquote>

However, it is being transformed to <blockquote>W<br />c</blockquote>.

The function responsible for this transformation in expensify-common needs to be reviewed.

The text input contains > which is captured by this regex:

https://github.com/Expensify/expensify-common/blob/6c07092648afd712251e25d05d54fcb303fda618/lib/ExpensiMark.js#L259

When the regex matches, the text is split into textSplitted and each line is processed separately.

https://github.com/Expensify/expensify-common/blob/6c07092648afd712251e25d05d54fcb303fda618/lib/ExpensiMark.js#L976

The issue occurs in this condition: if (Str.startsWith(textSplitted[i], '&gt;') && !insideCodefence) {

https://github.com/Expensify/expensify-common/blob/6c07092648afd712251e25d05d54fcb303fda618/lib/ExpensiMark.js#L985

This condition determines whether to process the line with > or not. In our case, a line like >test should not be processed as a quote.

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

To resolve the issue, we need to add another condition to this line:

if (Str.startsWith(textSplitted[i], '>') && !insideCodefence) {

We also need to check if the > is followed by a space or there's nothing after a consecutive >

We should maintain examples like > test, >>> test, > > >test, etc.

The following adjustment can be made:

// Check for the last occurrence of consecutive &gt; and get the character after it
const match = textSplitted[i].match(/(&gt;)+/);
let charAfterLastGt = '';
let nothingAfterGt = false

if (match) {
  const lastIndex = match.index + match[0].length;
  charAfterLastGt = textSplitted[i].charAt(lastIndex); // The character after the last consecutive &gt;
  nothingAfterGt = lastIndex >= textSplitted[i].length;
}

// We only want to modify lines starting with &gt; that is not codefence
// also if the chart after the last `>` is a space or there's nothing after the `>`        
if (Str.startsWith(textSplitted[i], '&gt;') && !insideCodefence && (charAfterLastGt === ' ' || nothingAfterGt)) {                 
  textToFormat += `${textSplitted[i]}\n`;
} else {

Tested on expensify-common with success.

43323-1.mp4

What alternative solutions did you explore?

@melvin-bot melvin-bot bot added the Overdue label Jun 10, 2024
@trjExpensify
Copy link
Contributor

Can repro, moving External.

@melvin-bot melvin-bot bot removed the Overdue label Jun 10, 2024
@trjExpensify trjExpensify added External Added to denote the issue can be worked on by a contributor Overdue labels Jun 10, 2024
@melvin-bot melvin-bot bot changed the title Chat-Quote Markdown without space is applied as a quote in sent chat but not in compose box [$250] Chat-Quote Markdown without space is applied as a quote in sent chat but not in compose box Jun 10, 2024
Copy link

melvin-bot bot commented Jun 10, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01352a9a30d580bacb

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

melvin-bot bot commented Jun 10, 2024

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

@melvin-bot melvin-bot bot removed the Overdue label Jun 10, 2024
@sobitneupane
Copy link
Contributor

sobitneupane commented Jun 12, 2024

@devguest07 Thanks for your proposal.

We should maintain examples like > test, >>> test, > > >test, etc.
(!/[a-zA-Z]/.test(charAfterGt)

I understand that we need to consider hierarchal quotes but won't it causes inconsistency when the character is not an alphabet. For example >12, >>, >& and so on.

@devguest07
Copy link
Contributor

@sobitneupane Sure, I can adjust the charAfterGt in my proposal to fit all those cases.

The idea is, after the > when it's not a space or a second >, we should not proceed to make it a quote.

Additionally, we can add examples like >12, >>, and >& to the tests inside expensify-common.

@sobitneupane
Copy link
Contributor

Sure, I can adjust the charAfterGt in my proposal to fit all those cases.

@devguest07 Can you please update your proposal to reflect the changes required?

@devguest07
Copy link
Contributor

@sobitneupane proposal updated

I reversed the logic, instead of seeking if there's some letter after the >, I am now making sure there's a space after a > and it's not some > alone.

I added a test to ExpensiMark

test('Test markdown quotes without spaces with a second line with a space', () => {
    const testString = '>test\n> test';
    const resultString = '&gt;test<br /><blockquote>test</blockquote>';
    expect(parser.replace(testString)).toBe(resultString);
});

and it's passed successfully.

@badeggg
Copy link
Contributor

badeggg commented Jun 17, 2024

Proposal

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

Inconsistency of display for same comment in composer box and chat history. Specifically:

>a
> b
> c

What is the root cause of that problem?

Regex /^(?:&gt;)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm is causing this condition if (match !== null) to true for comment:

>a
> b
> c

And condition Str.startsWith(textSplitted[i], '&gt;') is causing >a appended to textToFormat for further quote handling.

Which is not identical for same comment text in composer box. In composer box, >a is not regarded as quote.

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

We can either let composer box recognize >a as quote, or let chat history do not recognize >a as quote. Based on this comment of @dannymcclain, I think the design team prefer the former one(recognize >a as quote).

To achieve former behavior, we should change regex from:

const regex = /^(?:&gt;)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm;

to

const regex = /^(?:&gt;)+ *(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm;

, from matching '1 or more' spaces to matching '0 or more' spaces.

Similar change should be applied to this regex too.

To achieve later behavior, we should change '&gt;' to:

'&gt; '

, matching one space after &gt;

What alternative solutions did you explore? (Optional)

N/A

@sobitneupane
Copy link
Contributor

This issue might be in the scope of #42082. Asked here

@melvin-bot melvin-bot bot removed the Overdue label Jun 17, 2024
Copy link

melvin-bot bot commented Jun 17, 2024

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

@sobitneupane
Copy link
Contributor

@trjExpensify Let's hold this issue as it will probably be covered by #42082

@BrtqKr
Copy link
Contributor

BrtqKr commented Jun 18, 2024

Probably the same as I mentioned here. I'll let you know if it's not

@trjExpensify trjExpensify changed the title [$250] Chat-Quote Markdown without space is applied as a quote in sent chat but not in compose box [Hold #42082] [$250] Chat-Quote Markdown without space is applied as a quote in sent chat but not in compose box Jun 18, 2024
@trjExpensify
Copy link
Contributor

Put it on hold!

@BrtqKr
Copy link
Contributor

BrtqKr commented Jun 18, 2024

Ok, unlike the second issue it's unrelated, but it looks like a regex swap, so I can switch it in that PR I've mentioned

@trjExpensify
Copy link
Contributor

Great! Let's link that PR to this issue as well then. :)

Copy link

melvin-bot bot commented Jun 21, 2024

@trjExpensify, @sobitneupane Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label Jun 21, 2024
@trjExpensify
Copy link
Contributor

I think we might be good here?

@trjExpensify
Copy link
Contributor

@BrtqKr confirming this issue can be closed?

@BrtqKr
Copy link
Contributor

BrtqKr commented Jun 24, 2024

@trjExpensify it still has to be enabled in the expensify/app, but after this thing yes

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 Overdue labels Jun 24, 2024
@trjExpensify trjExpensify changed the title [Hold #42082] [$250] Chat-Quote Markdown without space is applied as a quote in sent chat but not in compose box [Hold #44262] [$250] Chat-Quote Markdown without space is applied as a quote in sent chat but not in compose box Jun 25, 2024
@trjExpensify
Copy link
Contributor

Okay great, I'm going to update the issue number we're held on.

Copy link

melvin-bot bot commented Jul 10, 2024

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Jul 17, 2024
Copy link

melvin-bot bot commented Jul 17, 2024

This issue has not been updated in over 15 days. @trjExpensify, @sobitneupane eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@trjExpensify
Copy link
Contributor

Deployed to prod three days ago: #44262 (comment)

So we can close this.

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. 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 Monthly KSv2 Reviewing Has a PR in review
Projects
No open projects
Archived in project
Development

No branches or pull requests

6 participants