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 for payment 2023-05-25] [$1000] Line break before heading is missing in editing mode #17998

Closed
6 tasks done
kavimuru opened this issue Apr 26, 2023 · 39 comments
Closed
6 tasks done
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kavimuru
Copy link

kavimuru commented Apr 26, 2023

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


Action Performed:

  1. Go to any chat
  2. Send a new comment
test

# heading
  1. Edit the comment and notice the text in editing composer is
test
# heading

Expected Result:

The line break before heading shouldn't be missing

Actual Result:

The line break before heading is missing

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.5-5
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

Recording.363.mp4
Screen.Recording.2023-04-25.at.10.07.09.AM.mov

Expensify/Expensify Issue URL:
Issue reported by: @eh2077
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1682388776064199

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01ea44f382867687f1
  • Upwork Job ID: 1651431771500584960
  • Last Price Increase: 2023-04-27
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Apr 26, 2023
@MelvinBot
Copy link

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

@MelvinBot
Copy link

MelvinBot commented Apr 26, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@dukenv0307
Copy link
Contributor

Proposal

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

Line break before heading is missing in editing mode

What is the root cause of that problem?

Draft message is display by htmlToMarkdown function. htmlToMarkdown function use htmlToMarkdownRules to convert html tag to mark down

const draftMessage = parser.htmlToMarkdown(this.props.draftMessage).trim();

And htmlToMarkdownRules in ExpensiMark lib has a rule for h1 tag:

name: 'heading1',
regex: /\s*<(h1)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))\s*/gi,
replacement: '[block]# $2[block]',

With this regex it replace \s*<h1> by [block]#. So all line break before heading is replaced by one line break.

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

Replace regex rule for h1 in htmlToMarkdownRules by /<(h1)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi

What alternative solutions did you explore? (Optional)

NA

Result

Screencast.2023-04-26.17.17.42.mp4

@kadiealexander
Copy link
Contributor

Was able to reproduce:

2023-04-27_15-38-08.mp4

@kadiealexander kadiealexander added the External Added to denote the issue can be worked on by a contributor label Apr 27, 2023
@melvin-bot melvin-bot bot changed the title Line break before heading is missing in editing mode [$1000] Line break before heading is missing in editing mode Apr 27, 2023
@MelvinBot
Copy link

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

@MelvinBot
Copy link

Current assignee @kadiealexander is eligible for the External assigner, not assigning anyone new.

@MelvinBot
Copy link

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 27, 2023
@MelvinBot
Copy link

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

@eh2077
Copy link
Contributor

eh2077 commented Apr 27, 2023

Proposal

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

Line break before heading is missing in editing mode

What is the root cause of that problem?

When editing a comment, we call method htmlToMarkdown to convert draftMessage which is equal to message[0].html to markdown, see

const draftMessage = parser.htmlToMarkdown(this.props.draftMessage).trim();

The initial draft message

test<br /><h1>heading</h1>

is converted to

test\n<h1>heading</h1>

by applying newline rule
and then it's converted into

test[block]# heading[block]

by applying html-heading1-to-markdown-heading rule.
And finally the first special separator [block] is converted to newline \n in method replaceBlockWithNewLine
So we get following text in the editing composer

test
# heading

Based on the above analysis, the root cause is that the line break before heading is eliminated in html-heading1-to-markdown-heading rule.
The regex

regex: /\s*<(h1)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))\s*/gi,

matches the \n before <h1> and eliminates it in the replacement function.

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

To fix this issue, we should retain line break before heading1. To achieve this, we should match whitespaces but not newlines before string <h1>.
The current prefix regex \s*
image
We can replace the prefix regex \s* with [^\S\r\n]* to skip newlines, see SO link about the new regex.
image

So the new regex for html-heading1-to-markdown-heading rule is

regex: /[^\S\r\n]*<(h1)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))\s*/gi,

What alternative solutions did you explore? (Optional)

Can we just remove the prefix regex \s*?
I don't think it's a good idea as the method htmlToMarkdown accepts html string as input. So it's possible to have an input that need to remove normal spaces before <h1>, like for html string input

this line has a <h1>heading1</h1> in the middle of the line

which is test case from the lib expensify-common.

@melvin-bot melvin-bot bot added the Overdue label May 1, 2023
@eVoloshchak
Copy link
Contributor

@dukenv0307, I don't think we should remove the \s* prefix, that's essentially reverting Expensify/expensify-common@58f5320

@eh2077, thank's for the analysis and a detailed explanation, I think that's the correct approach.
I did also found a similar issue, could you take a look at this please?

test

# heading

test

is turned into

test

# heading
test

@eh2077
Copy link
Contributor

eh2077 commented May 2, 2023

@eVoloshchak Sure. I think we can fix the issue of removing line break after heading as well if it’s not an intended feature the product team want.

@melvin-bot melvin-bot bot added the Overdue label May 3, 2023
@kadiealexander
Copy link
Contributor

Yeah let's fix that and prevent the automatic removal of line breaks too, please!

@melvin-bot melvin-bot bot removed the Overdue label May 4, 2023
@eh2077
Copy link
Contributor

eh2077 commented May 4, 2023

Yeah let's fix that and prevent the automatic removal of line breaks too, please!

Hi @eVoloshchak , as @kadiealexander has confirmed we should fix the removing ending line breaks issue too, I think we can apply the same regex piece to fix both removing line breaks issue together. And I found another reason that we should them is that we apply newline rule before heading rule, so it's obviously buggy to removing starting and ending line breaks of heading.

@eVoloshchak
Copy link
Contributor

@eh2077, sounds good, let's get the PR going
@kadiealexander, could you assign @eh2077 to the job please?

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label May 7, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 7, 2023

📣 @eh2077 You have been assigned to this job by @kadiealexander!
Please apply to this job in Upwork and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot
Copy link

melvin-bot bot commented May 18, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@eVoloshchak] The PR that introduced the bug has been identified. Link to the PR:
  • [@eVoloshchak] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@eVoloshchak] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@eVoloshchak] Determine if we should create a regression test for this bug.
  • [@eVoloshchak] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@kadiealexander] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels May 24, 2023
@kadiealexander
Copy link
Contributor

kadiealexander commented May 24, 2023

@eVoloshchak please don't forget the checklist above!

Assigned: May 8th 2023 10:52am (GMT+12)
First approved by C+: May 11th 5:11am (GMT+12)
Merged: May 14th 2023 10:32am (GMT+12)

Offers sent to @eh2077 for job + reporting bonus, and @eVoloshchak for C+.

@kadiealexander
Copy link
Contributor

Reassigning to get this paid tomorrow as I'm OOO.

@kadiealexander kadiealexander removed the External Added to denote the issue can be worked on by a contributor label May 25, 2023
@kadiealexander kadiealexander removed their assignment May 25, 2023
@kadiealexander kadiealexander added the External Added to denote the issue can be worked on by a contributor label May 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 25, 2023

Triggered auto assignment to @Christinadobrzyn (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@melvin-bot
Copy link

melvin-bot bot commented May 25, 2023

Current assignee @eVoloshchak is eligible for the External assigner, not assigning anyone new.

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label May 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 25, 2023

Current assignee @mountiny is eligible for the External assigner, not assigning anyone new.

@kadiealexander kadiealexander removed the Help Wanted Apply this label when an issue is open to proposals by contributors label May 25, 2023
@kadiealexander
Copy link
Contributor

Thanks @Christinadobrzyn!

@mountiny
Copy link
Contributor

Lets add the bonus as i was at AppJS

@Christinadobrzyn
Copy link
Contributor

Paid out the jobs in Upwork

@eh2077 - reporting bonus + speed bonus + contributor
@eVoloshchak speed bonus + C+

@eVoloshchak - can you let me know about a regression test? Thanks!

@melvin-bot melvin-bot bot added the Overdue label May 29, 2023
@mountiny
Copy link
Contributor

@eVoloshchak can you please follow up on the checklist above

@Christinadobrzyn @eVoloshchak I dont think we need a regression test for this

@melvin-bot melvin-bot bot removed the Overdue label May 29, 2023
@kadiealexander
Copy link
Contributor

Thanks for helping with this while I as away @Christinadobrzyn!!

@eVoloshchak
Copy link
Contributor

eVoloshchak commented May 30, 2023

Will finish the BZ checklist tomorrow
I think the regression test is needed here, this is something that could easily break, will propose a solution

@eVoloshchak
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: Add h1 markdown expensify-common#468

  • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/expensify-common/pull/468/files#r1212251731

  • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: This is a typical markdown issue, we already have an item in the reviewer checklist to catch similar issues sooner If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.

  • Determine if we should create a regression test for this bug. Thinking about it again, we don't need a regression test I think. We already have unit tests for this, no need to have a redundant manual test for something that's already automated

@Christinadobrzyn
Copy link
Contributor

Sounds good! Thanks for clarifying about the regression test @eVoloshchak - I think this can be closed as complete. right?

cc @mountiny

@kadiealexander
Copy link
Contributor

I agree @Christinadobrzyn, @mountiny if you disagree please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

8 participants