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

[$250] Chat - After editing nested quote message, the markdown is removed #47951

Closed
1 of 6 tasks
lanitochka17 opened this issue Aug 23, 2024 · 86 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Monthly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Aug 23, 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: 9.0.24-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4884121
Email or phone of affected tester (no customers): applausetester+vd_web082324@applause.expensifail.com
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to https://staging.new.expensify.com/
  2. Log in
  3. Go to any chat
  4. Send a nested quote message, like "> > test"
  5. Verify that it looks as expected on the chat
  6. Edit the message

Expected Result:

The markdown should still be displayed after editing the message

Actual Result:

The quote markdown effect is removed after editing a nested quote message

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

Add any screenshot/video evidence

Bug6580735_1724447327796.bandicam_2024-08-23_17-01-00-816.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a7ea8bf9646df697
  • Upwork Job ID: 1829295392648638850
  • Last Price Increase: 2024-08-29
Issue OwnerCurrent Issue Owner: @fedirjh
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 23, 2024
Copy link

melvin-bot bot commented Aug 23, 2024

Triggered auto assignment to @twisterdotcom (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.

@lanitochka17
Copy link
Author

@twisterdotcom 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

@lanitochka17
Copy link
Author

We think that this bug might be related to #vip-vsp

@bernhardoj
Copy link
Contributor

Proposal

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

After editing a nested quote markdown, the quote markdown is removed.

What is the root cause of that problem?

When we send > > test and edit the message, the markdown becomes >> test because we add the > without space and only add the space after the >. We can change that but I want to focus on a real issue explained below.
https://github.com/Expensify/expensify-common/blob/d11466167bc562447d2dfdad624145040153efae/lib/ExpensiMark.ts#L624

A quote markdown requires a space after >, for example, > test. But if we have a nested quote, >> test, there is an inconsistent logic when parsing it. If we see the quote markdown regex, we allow the nested quote without spaces between >, so >> test is a valid nested quote.
https://github.com/Expensify/expensify-common/blob/d11466167bc562447d2dfdad624145040153efae/lib/ExpensiMark.ts#L376

modifyTextForQuote is responsible to process the matched text (>> test) into the HTML form. It splits the text by new line and process each line whether it should be converted to a quote HTML or not. On each line, it checks whether the line starts with > or not.
https://github.com/Expensify/expensify-common/blob/d11466167bc562447d2dfdad624145040153efae/lib/ExpensiMark.ts#L1138

This shows that the logic doesn't cover the case of nested quote yet. So, you don't need to edit the message but just sends >> test and it won't be converted to a quote (the live markdown converts it to quote though because it doesn't get through modifyTextForQuote processing).

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

To allow nested quote have optional space between >, we can update the logic to accept either space or another > after > (we can use regex to shorten it, ^>(>| ))

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

This will convert it to markdown for below inputs:

> > test
>> test

@ChavdaSachin
Copy link
Contributor

ChavdaSachin commented Aug 25, 2024

Edited by proposal-police: This proposal was edited at 2024-08-30 20:43:57 UTC.

Proposal

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

Editing quote markdown message does not work as desired

What is the root cause of that problem?

RCA for the issue is -
HTML to markdown parsing rule does not reproduce equivalent Markdown.
There are 2 issues -

  • when editing nested quotes, returned text does not contain space in between two '>' s.
  • when editing multiline quotes, when preceding line have more quote than following line, no '>' for following line is returned

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

So, to tackle this we need to completely redesign

            {
                name: 'quote',
                regex: /<(blockquote|q)(?:"[^"]*"|'[^']*'|[^'">])*>(([\s\S]*?)<\/\1>)+(?![^<]*(<\/pre>|<\/code>))/gi,
                replacement: (_extras, _match, _g1,g2) => {
                    // We remove the line break before heading inside quote to avoid adding extra line
                    let resultString = _match
                        .replace(/\n?(<h1># )/g, '$1')
                        .replace(/(<h1>|<\/h1>)+/g, '\n')
                        .replace(/(<\/blockquote>)+/g, (match)=> { match + '\n' })
                        .trim()
                        .split('\n');
                    // Wrap each string in the array with <blockquote> and </blockquote>
                    let depth =0;
                    resultString = resultString.map((line) => {
                        let modifiedLine = line;
                            depth+= modifiedLine.match(/<blockquote>/gi)?.length || 0;
                            modifiedLine = modifiedLine.replace(/<blockquote>/gi, '');
                            modifiedLine = modifiedLine.replace(/<\/blockquote>/gi, '');
                            let resultString = `${'<blockquote>'.repeat(depth)}${modifiedLine}${'</blockquote>'.repeat(depth)}`;
                            depth-=line.match(/<\/blockquote>/gi)?.length || 0;
                            return resultString;
                    });
                    resultString = resultString
                        .map((text) => {
                        let modifiedText = text;
                        let depth;
                        do {
                            depth = (modifiedText.match(/<blockquote>/gi) || []).length;
                            modifiedText = modifiedText.replace(/<blockquote>/gi, '');
                            modifiedText = modifiedText.replace(/<\/blockquote>/gi, '');
                        } while (/<blockquote>/i.test(modifiedText));
                        return `${'> '.repeat(depth)}${modifiedText}`;
                    })
                     .join('\n');
                    return `<blockquote>${resultString}</blockquote>`;
                },
            },
                if ((textSplitted[i].match(/^( *(&gt; )+)+ /gm)  || isLastBlockquote) && !insideCodefence) {

What alternative solutions did you explore? (Optional)

Changing this rule slightly would provide correct markdown equvalent.
Change Here from -

return ${'>'.repeat(depth)} ${modifiedText};
To -

return ${'> '.repeat(depth)}${modifiedText};
changed blankspace position.
We could also use same approach with little bit of modification if we want to add support for multiple '>'s without space in between.

@melvin-bot melvin-bot bot added the Overdue label Aug 26, 2024
Copy link

melvin-bot bot commented Aug 27, 2024

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

Copy link

melvin-bot bot commented Aug 29, 2024

@twisterdotcom Eep! 4 days overdue now. Issues have feelings too...

@twisterdotcom
Copy link
Contributor

Agree, this one was simple to reproduce. Apologies for the time, I am just back from OOO.

@melvin-bot melvin-bot bot removed the Overdue label Aug 29, 2024
@twisterdotcom twisterdotcom added the External Added to denote the issue can be worked on by a contributor label Aug 29, 2024
@melvin-bot melvin-bot bot changed the title Chat - After editing nested quote message, the markdown is removed [$250] Chat - After editing nested quote message, the markdown is removed Aug 29, 2024
Copy link

melvin-bot bot commented Aug 29, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01a7ea8bf9646df697

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

melvin-bot bot commented Aug 29, 2024

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

@ChavdaSachin
Copy link
Contributor

updated proposal, added alternative solution which looks more sensible to me

Copy link

melvin-bot bot commented Sep 2, 2024

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

@melvin-bot melvin-bot bot added the Overdue label Sep 2, 2024
@twisterdotcom
Copy link
Contributor

Bump @fedirjh on these proposals

@fedirjh
Copy link
Contributor

fedirjh commented Sep 4, 2024

@bernhardoj's Proposal looks good to me. Let's use the regex as it covers different variations of nested quotes with spaces.

🎀 👀 🎀 C+ reviewed

@melvin-bot melvin-bot bot removed the Overdue label Sep 4, 2024
Copy link

melvin-bot bot commented Sep 4, 2024

Triggered auto assignment to @cead22, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@ChavdaSachin
Copy link
Contributor

@fedirjh It looks like two blockquotes must be separated by space is recommended design feature. So, we might need a design review on this one. check #45154 (comment) .

@bernhardoj
Copy link
Contributor

When we send > > test and edit the message, the markdown becomes >> test because we add the > without space and only add the space after the >. We can change that but I want to focus on a real issue explained below.
https://github.com/Expensify/expensify-common/blob/d11466167bc562447d2dfdad624145040153efae/lib/ExpensiMark.ts#L624

Just a note that if we require space for each >, I already write an explanation about that in the root cause section.

@Skalakid
Copy link
Contributor

Hello, today I continued fixing HTML to markdown parsing logic. Tomorrow I will clean up the code and push the changes to the PR so we can start merging it

Copy link

melvin-bot bot commented Nov 25, 2024

@cead22, @twisterdotcom, @fedirjh, @Skalakid 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 Nov 25, 2024
@Skalakid
Copy link
Contributor

Hello, I'm adding last touches to my PR with the solution for this issue. Will open it for the review today

@melvin-bot melvin-bot bot removed the Overdue label Nov 26, 2024
Copy link

melvin-bot bot commented Dec 2, 2024

@cead22, @twisterdotcom, @fedirjh, @Skalakid Eep! 4 days overdue now. Issues have feelings too...

@melvin-bot melvin-bot bot added the Overdue label Dec 2, 2024
@Skalakid
Copy link
Contributor

Skalakid commented Dec 2, 2024

PR is waiting for the C+ review

@melvin-bot melvin-bot bot removed the Overdue label Dec 2, 2024
Copy link

melvin-bot bot commented Dec 5, 2024

@cead22, @twisterdotcom, @fedirjh, @Skalakid Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added the Overdue label Dec 5, 2024
@twisterdotcom
Copy link
Contributor

This was merged, so it is waiting on a deploy now?

Copy link

melvin-bot bot commented Dec 9, 2024

@cead22, @twisterdotcom, @fedirjh, @Skalakid 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@Skalakid
Copy link
Contributor

Skalakid commented Dec 9, 2024

The PR has been merged. We will bump the Expensify-common together with the next Live Markdown bump since some new breaking changes were introduced there

Copy link

melvin-bot bot commented Dec 10, 2024

@cead22, @twisterdotcom, @fedirjh, @Skalakid Still overdue 6 days?! Let's take care of this!

@Skalakid
Copy link
Contributor

Skalakid commented Dec 11, 2024

Waiting for this PR to be merged, since it bumps the Live Markdown and expensify-common libraries

Copy link

melvin-bot bot commented Dec 11, 2024

@cead22, @twisterdotcom, @fedirjh, @Skalakid 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

@twisterdotcom
Copy link
Contributor

Would be nice to get an update on this one. Is it likely be getting daily updates, or should we make it weekly for now if we're beholden to some other deployment schedules?

@Skalakid
Copy link
Contributor

The solution is ready; we are only waiting to bump the libraries in the app. As I wrote above today, this will be done by this PR. For now, we can make it weekly, but the changes should be merged this week if nothing critical appear

@fedirjh
Copy link
Contributor

fedirjh commented Dec 11, 2024

@Skalakid Do the changes from this PR (Expensify/expensify-common#820) be shipped with that PR #53627 ?

@melvin-bot melvin-bot bot removed the Overdue label Dec 11, 2024
@twisterdotcom twisterdotcom added Weekly KSv2 and removed Daily KSv2 labels Dec 11, 2024
@Skalakid
Copy link
Contributor

@fedirjh yes, they bumped the expensify-common to the version that contains my changes

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Jan 6, 2025
Copy link

melvin-bot bot commented Jan 6, 2025

This issue has not been updated in over 15 days. @cead22, @twisterdotcom, @fedirjh, @Skalakid 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!

@fedirjh
Copy link
Contributor

fedirjh commented Jan 10, 2025

This seems to be fixed. I think this can be closed.

@twisterdotcom
Copy link
Contributor

Wait, with no payment?

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 Monthly KSv2
Projects
Status: LOW
Development

No branches or pull requests

8 participants